Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found: Can't resolve 'react-refresh/runtime' in create-react-app v4 #2957

Closed
Nightliss opened this issue Oct 27, 2020 · 7 comments · Fixed by facebook/create-react-app#9872

Comments

@Nightliss
Copy link

pnpm version:

5.10.2

Code to reproduce the issue:

  1. pnpx create-react-app test
  2. cd /test
  3. yarn start - this works
  4. rm -rf /node_modules, rm yarn.lock
  5. pnpm i
  6. pnpm start - getting error Module not found: Can't resolve 'react-refresh/runtime'

image

Expected behavior:

app compiles successfully

Actual behavior:

getting error Module not found: Can't resolve 'react-refresh/runtime'

Additional information:

  • node -v prints: v12.19.0
  • Windows, OS X, or Linux?: Windows10 Pro build 2004
@statianzo
Copy link
Contributor

statianzo commented Oct 27, 2020

react-refresh is a nested dependency of react-scripts, not the app itself.

Looks like it's new to CRA 4.0 from a few days ago

https://github.com/facebook/create-react-app/blob/95265c34ff9e1c0881c7d9acc37d17f465629fa2/CHANGELOG.md#400-2020-10-23

You can disable the injection of react-refresh/runtime by setting an environment variable FAST_REFRESH=false

FAST_REFRESH=false pnpm start

You could also fix it by adding a dependency pnpm add -D react-refresh so it's top level within node_modules.

@GonzaloRizzo
Copy link

Why pnpm does not install this dependency? It seems to be declared on webpack's package.json

@statianzo
Copy link
Contributor

Why pnpm does not install this dependency? It seems to be declared on webpack's package.json

pnpm does install it. It's just not hoisted to node_modules because the app's package.json doesn't contain react-refresh.

react-refresh-webpack-plugin is assuming the a flat node_modules when injecting react-refresh/runtime.

dependencies:
react-scripts 4.0.0
├─┬ @pmmmwh/react-refresh-webpack-plugin 0.4.2
│ └── react-refresh 0.8.3 peer
└── react-refresh 0.8.3

@merceyz
Copy link

merceyz commented Oct 31, 2020

Will be fixed upstream in facebook/create-react-app#9872

@hinell
Copy link

hinell commented Nov 6, 2020

Issue

  • I can confirm that this happens only if node_modules gets deleted. Otherwise it works fine
  • It's not an issue of the pnpm itself, rather, it's CRA fault as pointed above

Versions affected

  • linux Ubuntu, x86_64, NodeJS 12.18.3
  • linux Ubuntu, x86_64, NodeJS 15.0.1

yonixw added a commit to yonixw/MangaPrinter that referenced this issue Nov 19, 2020
guesant added a commit to guesant-archived/ui5-monorepo that referenced this issue Dec 10, 2020
Tem um bug acontecendo aqui, o react-scripts
não está detectando o react-refresh mesmo já estando
instalado.

Já tem um PR aberto no create-react-app para corrigir isso.

pnpm/pnpm#2957 (comment)
dbartholomae added a commit to startup-cto/christmas-delivery that referenced this issue Dec 10, 2020
The current create-react-app does not work with pnpm

See pnpm/pnpm#2957
@dkozar
Copy link

dkozar commented Dec 17, 2020

I noticed a typo above. It should be FAST_REFRESH and not FAST_REFESH.

@statianzo
Copy link
Contributor

I noticed a typo above. It should be FAST_REFRESH and not FAST_REFESH.

Fixed. Thanks 🙌

SonNg2k added a commit to GW-Web-Enterprise/ReactJS that referenced this issue Feb 4, 2021
eventualbuddha added a commit to votingworks/vxsuite that referenced this issue Jul 15, 2021
Because of the way pnpm installs `node_modules` on disk, the app didn't have the ability to load `react-refresh`. We fixed this in the other apps by installing `react-refresh` at the top level of the application, and the same fix works here.

See pnpm/pnpm#2957
mcansh added a commit to remix-run/remix that referenced this issue Mar 2, 2023
react-refresh is a dependency of remix-dev, not of your app.

so we can use require.resolve to find it. This fixes an issue where remix-dev would not work with pnpm.

see pnpm/pnpm#2957 (comment) for a similar issue in CRAv4 and how they fixed it there https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/230/files

Signed-off-by: Logan McAnsh <logan@mcan.sh>
mcansh added a commit to remix-run/remix that referenced this issue Mar 15, 2023
react-refresh is a dependency of remix-dev, not of your app.

so we can use require.resolve to find it. This fixes an issue where remix-dev would not work with pnpm.

see pnpm/pnpm#2957 (comment) for a similar issue in CRAv4 and how they fixed it there https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/230/files

Signed-off-by: Logan McAnsh <logan@mcan.sh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants