Add `resolve` configuration in Webpack to avoid using relative paths in `import`
See original GitHub issueHi guys.
I was wondering why don’t you added some config like this in Webpack, to start doing
import foo from 'components/foo';
instead of
import foo from '../../components/foo';
Is there any issue about it? Thank for your patience.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Getting rid of relative paths in imports using webpack alias
Getting rid of relative paths in imports using webpack alias ... You can add an alias under resolve option provided by web pack...
Read more >Module Resolution - webpack
A resolver is a library which helps in locating a module by its absolute path. A module can be required as a dependency...
Read more >Avoid relative import paths in React.js using Webpack aliases
By setting resolve.aliases in your Webpack config ( webpack.config.js ), you can make the process of importing modules pretty easy. So, ...
Read more >Webpack can't resolve relative path import express static
Since you're setting the extensions: [".ts", ". · You specify .ts and . · If you are using Typescript, you will need to...
Read more >ES6 Import Statement Without Relative Paths Using Webpack
Use this in your Webpack v1.x configuration. You might already have a 'resolve' setting in there. Keep everything there, but add a root...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s been suggested quite a few times before (please search for “absolute imports” in issues). We won’t be supporting it on Webpack level because it is incompatible with Node resolution mechanism.
But if you’d like, you can work around it by adding
to your
.env
file in project root.Then this will work. Alternatively you can symlink
node_modules/components
tosrc/components
and it will work too.Hope this helps!
Adding the path to
.env
file doesn’t seem to work.I generated a new project using
create-react-app test
, editedindex.js
toimport App from 'App';
instead ofimport App from './App';
and all I’m getting isThe only way I could get it working was by changing the
start
script to be"start": "NODE_PATH=src react-scripts start"
.Is there a reason why my
.env
file is not being picked up?