How to import file from outside /components in react

前端 未结 3 1085
情书的邮戳
情书的邮戳 2021-01-22 02:03

My folder structure is as follows:

In my App.Js (which is under the components folder), I have:

import variables from \'/src/EnvVariables/varia         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-22 02:28

    if you just need to import your any file to a component : (just follow this steps)

    1. Simply you can create a .env file in src directory .
    2. In that .env file you need to add this line only NODE_PATH = src/
    3. Then you can write import "Home.css" (your file name will be here) to a component from src, it will take it easily.
    4. Run the program again , then you will get the same error, but take it easy and just you have to do fully start your program with the npm start from a new terminal.

提交回复
热议问题