Document src/node_modules as official solution for absolute imports
See original GitHub issueAfter a long discussion in #741 it seems to me that src/node_modules
seems like the best solution for absolute imports.
It has the following benefits:
- Doesn’t rely on symlinks (they don’t work well on Windows).
- Works with IDEs and any existing tooling because it relies on Node resolution mechanism.
- If you really want to, you can run
ln -s src/node_modules src/packages
and use the “nicer”packages
(or any other) folder.
This issue is a call to help to make this approach the official one. We need to:
- Document it
- Make Jest preprocess this subfolder #607
- Make Jest run tests in it #1042
- Fix any other integration issues we find
If you want to work on either please leave a comment and then submit a PR! Cheers.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:45
- Comments:30 (12 by maintainers)
Top Results From Across the Web
Absolute vs Relative Imports in Python
In this tutorial, you'll not only cover the pros and cons of absolute and relative ... You can find out more about imports...
Read more >Why and How to Use Absolute Imports in React
Easily copy-paste the code with imports into another file in the project and not have to tinker with import paths. It is short...
Read more >Understand and Configure Absolute Import Paths in JavaScript
Variables, functions, and classes that are declared in a module need to be explicitly exported. All modules intended to be used in other...
Read more >Making Life Easier with Absolute Imports - React in Javascript ...
According to create-react-app Docs, We can use absolute imports in our react project by configuring a jsconfig. json / tsconfig. json (for ...
Read more >Absolute and Relative Imports in Python - GeeksforGeeks
Python modules can get access to code from another module by importing the file/function using import. The import statement is the most ...
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 FreeTop 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
Top GitHub Comments
In my mental model
node_modules
is something I can easilyrm -rf
and regenerate w/o worries to lose anything. I never expect any app code in there. A lot of various configs ignore it for the same reason: in most of the cases, it’s something not related to user’s code. Also, usually you have to move a whole app in this directory.For absolute imports, it seems like it’d be a lot better to have some kind of special prefix and set up webpack’s alias functionality for it. For example, my personal projects use:
…after which you can reference files via…
You can also inject the same schema into Jest:
It keeps a clear distinction from npm-tracked
node_modules
, avoiding the “I can’t get it to work and I don’t understand why” potential of having overlapping names or having imports start with just./
.