react-scripts 4.0.1 absolute components import doesn't work
See original GitHub issueDescribe the bug
Absolute components import doesn’t work in 4.0.1 CRA version.
For example:
import React, { useState } from 'react';
import Todo from 'components/Todo';
I get this error `Module not found: Can’t resolve ‘components/Todo’ in ‘…/cra-project/src’
Folder components
is nested to src
folder.
The file .env
was added in the project root.
.env
file content
NODE_PATH=src/
When I change react-scripts
version from 4.0.1
to 3.4.4
absolute imports work fine.
Did you try recovering your dependencies?
Yes.
Environment
Environment Info:
current version of create-react-app: 4.0.1 running from /home/sergey-sedykh/.npm/_npx/12865/lib/node_modules/create-react-app
System: OS: Linux 5.4 Ubuntu 18.04.3 LTS (Bionic Beaver) CPU: (4) x64 Intel® Core™ i5-3330 CPU @ 3.00GHz Binaries: Node: 14.6.0 - /usr/local/bin/node Yarn: 1.22.4 - /usr/bin/yarn npm: 6.14.6 - /usr/local/bin/npm Browsers: Chrome: 85.0.4183.121 Firefox: 83.0 npmPackages: react: ^17.0.1 => 17.0.1 react-dom: ^17.0.1 => 17.0.1 react-scripts: 4.0.1 => 4.0.1 npmGlobalPackages: create-react-app: Not Found
Steps to reproduce
- Install project with CRA
- Create the file
.env
in the project root. - Add to the
.env
file next contentNODE_PATH=src/
- Use absolute components import
Expected behavior
Absolute module imports should work.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top GitHub Comments
Replace
NODE_PATH=./
in your.env
file by the following in tsconfig.jsonThis could be more explicit in the changelog.
None of those work for me in 2021 with
create-react-app@4.0.3