首页 > 解决方案 > Importing installed node modules vs importing css or other files in React

问题描述

Could someone explain why this:

import React from '../node_modules/react';

is the same as:

import React from 'react';

and this:

import './App.css';

is NOT the same as:

import 'App.css';   or import 'App.css';

in the later example I get a message that the file App.css can not be found in the src directory but it is there.

标签: react-nativedirectoryrouter

解决方案


It identifies the modules by name

But files it detects only by path As you will see in the documentation

module-name The module to import from. This is often a relative or absolute path name to the .js file containing the module. Certain bundlers may permit or require the use of the extension; check your environment. Only single quoted and double quoted Strings are allowed.

name Name of the module object that will be used as a kind of namespace when referring to the imports.


推荐阅读