Skip to content

"You attempted to import /.../esm/slicedToArray which falls outside of the project src/..." #24

@amagee

Description

@amagee

If I write a component that tries to use the React useState hook, I get the following error from the yarn start process:

Failed to compile.

Module not found: Error: You attempted to import /path/to/react/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/slicedToArray which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules/.

Note: I get the same error from a clean checkout of the full-sample repo.

I'm able to work around the problem by hacking out the check in ModuleScopePlugin.js in react-dev-utils:

diff --git a/react/node_modules/react-dev-utils/ModuleScopePlugin.js b/react/node_modules/react-dev-utils/ModuleScopePlugin.js
index e84d2b3..0c1cf46 100644
--- a/react/node_modules/react-dev-utils/ModuleScopePlugin.js
+++ b/react/node_modules/react-dev-utils/ModuleScopePlugin.js
@@ -56,6 +56,7 @@ class ModuleScopePlugin {
         // Find path from src to the requested file
         // Error if in a parent directory of all given appSrcs
         if (
+          false &&
           appSrcs.every(appSrc => {
             const requestRelative = path.relative(appSrc, requestFullPath);
             return (

but I'm sure there is a more sensible solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions