DEV Community

Discussion on: Using absolute imports in React app

Collapse
 
thuanpv1 profile image
thuanpv1

my project was created by the command npx create-react-app last year. I have just tried to apply your solution of importing other components. However, i still get the message "Module not found: Can't resolve '...". it looks like the import by this way is correct because i can jump into the component by pressing ctrl + left mouse click into the path. so i don't know why compiler doesn't recognize the new import path. have you ever bump into this kind of issue ? and what is your solution to cover this case ?

Collapse
 
dominikilnicki profile image
Dominik Ilnicki

Hi, that solution works only with projects created using create-react-app in version 3 (released in April 2019). If your project was bootstrapped with v2 you can use old school way to achieve absolute imports. Create .env file with that line NODE_PATH=src/. That should work for you.