question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Completely disallow importing from outside of src/, packages/ or node_modules/

See original GitHub issue

There 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:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:25 (7 by maintainers)

github_iconTop GitHub Comments

27reactions
shaneosullivancommented, Oct 22, 2017

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…

  • /app1/src/
  • /app2/src/
  • /shared/

I understand that (b) is forbidden. Does that just leave me with (a)?

14reactions
Hurtakcommented, Dec 2, 2017

What is currently the best solution to import components across CRA apps in monorepo? Yarn workspaces, symlinks?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found