Support absolute paths with packages/ folder
See original GitHub issueWe’ve been using Lerna in Create React App, and I really like its approach. I think we should support a similar workflow (even without Lerna itself) for the “absolute paths” feature.
I imagine it working like this:
- In addition to
src
, you can create a special top-level folder calledpackages
. - Inside
packages
, you can create folders likeapp
,stuff
,lol
, and they all “see” each other so you can import things fromapp/whatever.js
orlol/wow.js
. You can also import any packages fromsrc
(but not vice versa). The entry point is stillsrc/index.js
. - We won’t add any magic handling that breaks Node resolution mechanism. Instead, whenever you
npm start
,npm test
, ornpm run build
, we will run a utility that creates symlinks fromnode_modules
of the root project to every folder inpackages
. It reports a hard error if there is a conflict. This means the authors can add server rendering after ejecting without scratching their heads, and that all the tooling assuming Node resolution mechanism keeps working.
package.json
public/
src/
index.js # can import app/banana.js or harry-potter/wand.js
packages/
app/
banana.js # can import harry-potter/wand.js
harry-potter/
wand.js # can import app/banana.js
node_modules/
app -> packages/app
harry-potter -> packages/harry-potter
other-deps
Am I missing why this would be a bad idea?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:47
- Comments:86 (24 by maintainers)
Top Results From Across the Web
How to import a folder with absolute path as package?
The path is app/base/admin/crud/__init__.py . I want to import an entire folder as a package like this: import app.base ...
Read more >Working Directories, Absolute and Relative Paths ...
An absolute path is a path that contains the entire path to the file or directory that you need to access. This path...
Read more >Importing with Absolute Paths in JavaScript/TypeScript using ...
How to use absolute paths in JavaScript and TypeScript to improve your import statements, using the right webpack configuration.
Read more >Java File Path, Absolute Path and Canonical Path
Let's see different cases of the file path in java with a simple program. package com.journaldev.files; import java.io.File; import java.io.
Read more >Paths explained: Absolute, relative, UNC, and URL—Help
After navigating to this directory, a relative path will use D:\Data\Shapefiles\Soils as the current directory (until you navigate to a new directory, at...
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
I think it may be a good idea to consider teaching people this pattern:
This seem to not only work with create-react-app, but everywhere. You don’t need any symlinks or whatever.
Glad I stumbled upon this. I’ve put
NODE_PATH=src/
in my.env
file and now I can use thisimport Button from 'components/Button'
from any file. Thank-you all.