Completely disallow importing from outside of src/, packages/ or node_modules/
See original GitHub issueThere shouldn’t be multiple conflicting ways to do the same thing. Currently we allow importing JS from anywhere but we don’t process it with Babel if it is outside src
. This is slightly confusing and inconsistent. It also allows invalid/unsupported patterns like importing from public
folder (which exists for a completely different purpose), or from build
.
After #741 is implemented and we have a first-class support for multiple top-level modules in a single repo, I think we should completely disallow importing JS or assets from anywhere else. Then we would have a clear picture of what each directory is for:
node_modules # JS unprocessed by Babel, third party modules
src # JS processed by Babel, entry point
packages # JS processed by Babel, additional self-contained "packages"
public # escape hatch for non-module assets, never processed
build # build output, never processed
<other folders> # docs and other resources, never part of build output
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:25 (7 by maintainers)
Top Results From Across the Web
The create-react-app imports restriction outside of src directory
This is special restriction added by developers of create-react-app. It is implemented in ModuleScopePlugin to ensure files reside in src/ .
Read more >Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >eslint-plugin-import - npm
This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import ...
Read more >Common TypeScript module problems and how to solve them
Problem 1: Irregular location of dependencies ; node_modules in the ; src directory even though ; node_modules is located outside the ; src...
Read more >Cannot use import statement outside a module [React ...
Note that if you're using the latest version of TypeScript for your Node app, the tsconfig.json file has default rules that prevent the ......
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
What’s the suggested solution for the following setup:
I have two CRA-created apps. They each need a number of shared custom components that I also wrote. Do I need to
(a) Host these component files in one app, and manually/scripted copy them over into the src folder of the other app every time I change them? (b) Store them in a separate sibling folder and reach outside the app? eg…
I understand that (b) is forbidden. Does that just leave me with (a)?
What is currently the best solution to import components across CRA apps in monorepo? Yarn workspaces, symlinks?