create-react-app: Module not found: react-refresh/runtime.js falls outside of the project src/
Describe the bug
Morning, i upgraded my project to react-scripts V5 and now the console is showing many logs about this
`ERROR in ./src/services/store/actions/index.js 1:40-119 Module not found: Error: You attempted to import …/node_modules/react-refresh/runtime.js 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/. @ ./src/services/store/reducers/index.js 14:0-40 27:9-19 @ ./src/services/store/index.js 8:0-34 38:28-36 @ ./src/index.js 13:0-40 22:9-17
ERROR in ./src/services/store/actions/sharedStore/index.js 1:40-119 Module not found: Error: You attempted to import …/node_modules/react-refresh/runtime.js 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/. @ ./src/services/store/reducers/sharedStore/index.js 4:0-86 11:9-26 16:9-31 @ ./src/services/store/reducers/index.js 13:0-47 65:21-39 @ ./src/services/store/index.js 8:0-34 38:28-36 @ ./src/index.js 13:0-40 22:9-17
ERROR in ./src/services/store/index.js 1:40-119 Module not found: Error: You attempted to import …/node_modules/react-refresh/runtime.js 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/. @ ./src/index.js 13:0-40 22:9-17 `
Did you try recovering your dependencies?
yes, i deleted node_modules and yarn.lock and nothing
Which terms did you search for in User Guide?
react-refresh runtime error
Environment
yarn version = 1.22.5 node version = 16.13.0 react version = 18.0.0-rc
Steps to reproduce
- installed new version
- yarn start (react-scripts start)
- console full of errors
Expected behavior
the project should works like the previous version
Actual behavior
ERROR in ./src/services/store/actions/index.js 1:40-119 Module not found: Error: You attempted to import …/node_modules/react-refresh/runtime.js 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/. @ ./src/services/store/reducers/index.js 14:0-40 27:9-19 @ ./src/services/store/index.js 8:0-34 38:28-36 @ ./src/index.js 13:0-40 22:9-17
ERROR in ./src/services/store/actions/sharedStore/index.js 1:40-119 Module not found: Error: You attempted to import …/node_modules/react-refresh/runtime.js 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/. @ ./src/services/store/reducers/sharedStore/index.js 4:0-86 11:9-26 16:9-31 @ ./src/services/store/reducers/index.js 13:0-47 65:21-39 @ ./src/services/store/index.js 8:0-34 38:28-36 @ ./src/index.js 13:0-40 22:9-17
ERROR in ./src/services/store/index.js 1:40-119 Module not found: Error: You attempted to import …/node_modules/react-refresh/runtime.js 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/. @ ./src/index.js 13:0-40 22:9-17
Reproducible demo
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 35
- Comments: 18
Commits related to this issue
- Update dependencies - "overrides" block added to fix "Module not found" error - for more, see https://github.com/facebook/create-react-app/issues/11810#issuecomment-1108392202 — committed to chicagopcdc/gearbox-frontend by bobaekang 4 years ago
- fix: `npm install` by adding `overrides` for rr Credit for this fix goes to https://github.com/facebook/create-react-app/issues/11810#issuecomment-1152378894. — committed to tide-app/tide by hamirmahal 4 years ago
- Fix build error - re: https://github.com/facebook/create-react-app/issues/11810#issuecomment-1632242812 — committed to k3vnb/modular_montage by k3vnb 3 years ago
- pc - fix problem where npm start refuses to start because of error related to react-refresh See: https://github.com/facebook/create-react-app/issues/11810#issuecomment-1108392202 for more info on the... — committed to ucsb-cs156/proj-courses by pconrad 2 years ago
- pc - fix problem where npm start refuses to start because of error related to react-refresh See: https://github.com/facebook/create-react-app/issues/11810#issuecomment-1108392202 for more info on the... — committed to ucsb-cs156/proj-courses by pconrad 2 years ago
Just adding a few more information to this thread. I had the issue because one package depended on version
">=0.10.0 <1.0.0"of react-refresh, while the others depended on"^0.11.0". This cause both version 0.11 and 0.12 to be installed. (Note that ^0.11.0 means >=0.11.0 <0.12.0.)Interestingly Yarn prioritized installing a single version of react-refresh over installing the latest versions, so with Yarn i only got version 0.11.0 installed.
Npm 8.3+ supports overrides, so I could fix my issue by adding this to my
package.jsonfile.Overriding to version 0.12.0 or ^0.12.0 would probably also have worked.
You saved my day! Thanks!
Worked like a charm! Recently migrated to Nx, was getting the above mentioned error. Finally got the project running with this approach.
Thank you, this helped me. Appreciate the help!
For others struggling with this I have found that moving all Storybook packages to
devDependencieswhilst leavingreact-scriptsandwebpackindependencieswill work. You’ll need to deletepackage-lock.jsonandnode_modulesafterwards and reinstall.Maybe something about the combination of Storybook,
react-scriptsandwebpackis confusingnpm.More notes (and a reproducible example project) here:
https://github.com/storybookjs/storybook/issues/17049#issuecomment-1004732920
Try checking if “react-refresh” has two versions being used by your app. The problem for most of us was that StoryBook was using a previous version (0.10) and CRA 5.0 needed a new one (0.11). Maybe you have another package using the older version too?
My man you saved my life. Worked like a charm
This is what was happening in my case.
Forcing them all to use the same version via yarn’s
resolutionsfixed this particular error.Then run
yarn install, which then providesHowever, the same cannot be said about the same errors stemming from
@pmmmwh/react-refresh-webpack-pluginbut that is off topic and a problem which I have not yet solved.Does not work in monorepo like lerna with --hoist option.
solved in storybook side with
6.5.0-alpha.5closing thisIssue: Resolving Dependency Conflicts with
react-refreshSteps to Reproduce:
Delete existing files:
node_modulesandpackage-lock.jsonfrom your project directory:Install
react-refreshglobally:Add an
overridesblock topackage.json:package.jsonfile:Reinstall dependencies:
Expected Behavior:
After following the steps above, the dependency issues related to
react-refreshshould be resolved, and the project should build/run without errors.Hey, thanks for the follow-up.
It ended up being an incomplete “reset” on my part. SB also wrecked the build phase tho so I scrapped it altogether for that project.
On Mon, Jan 3, 2022, at 18:24, Cristiano Faustino wrote:
– Christophe Porteneuve @.***
after remove
"@storybook/react": "^6.4.9",started to works, something there is breaking this