create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

react-scripts start is serving old data

Open Lagicrus opened this issue 4 years ago • 35 comments

Describe the bug

When using react scripts start to serve Dev data, the served JSX is old/cached when it breaks. For example, when I accidentally added ; by accident to the end of some code, it broke, and it gave me the popup to say so. But when I then fixed it, that broken code is still being shown to me in the error, even after I both reload the page and even do a forced reload. I have saved the file multiple times and even opened the file itself in a separate program to make sure that it is indeed "fixed", and it is. But webpack seems to think that nope, it is broken still.

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

Old code, serving old code, build not updating

Environment

System: OS: Windows 10 10.0.20279 CPU: (12) x64 AMD Ryzen 5 1600 Six-Core Processor Binaries: Node: 12.14.1 - E:\Program Files\nodejs\node.EXE Yarn: Not Found npm: 6.14.10 - E:\OneDrive\GitHub\talespire\site\node_modules.bin\npm.CMD Browsers: Chrome: 87.0.4280.88 Edge: Spartan (44.20279.1.0) Internet Explorer: 11.0.20279.1 npmPackages: react: ^16.14.0 => 16.14.0 react-dom: ^16.14.0 => 16.14.0 react-scripts: ^4.0.1 => 4.0.1 npmGlobalPackages: create-react-app: Not Found

Steps to reproduce

  1. Create a CRA App
  2. start the server to serve it to the client to work on
  3. add a error
  4. fix the error
  5. see no change

Expected behavior

The code to change in the browser & console when I changed the file itself

Actual behavior

It didn't change. Both console and the website give me this error image , but the code it references is this https://starb.in/BjDNGR.js This is even the case after, reloading the page, clearing cache, restarting the server, uninstalling it (4.0.1) and reinstalling ^3.4 and back again. Even removing that whole function, saving, and adding it back in doesn't fix. Breaking it will show the new error, but when that is fixed, it will show the old one and old code again. I got it to work once an hour ago and no idea how I did that.

Lagicrus avatar Dec 27 '20 10:12 Lagicrus

Oh my goodness I am having the same issue and I have no idea how to fix it. It is EXTREMELY frustrating (I initially typed this comment out completely in all caps). It appears to happen intermittently and I cannot find a fix or workaround.

mcchong avatar Jan 04 '21 21:01 mcchong

It seems to appear when running the dev sever (via npm start) mysteriously in tall grass or when I am making changes that really confuse the parser quickly (e.g. copy-pasting a block of code and then modifying it). It doesn't go away unless some webpack/babel god smiles upon you (I have had it fix itself while googling the issue).

I have tried:

  • Removing the file with the compile issue, reverting via git. (the compile issue remains and refers to a line that doesn't exist).
  • Removing the node_modules dir, re-running npm install
  • npm build usually also fails
  • Checking the global node_modules dir to see if there was some cache there (don't really have anything installed there except npm)
  • https://create-react-app.dev/docs/troubleshooting#npm-start-doesnt-detect-changes
  • Burnt offering of a miniature goat.

I'm working through the react-scripts build process now to figure out a workaround but any guidance anyone might have would be greatly appreciated.

mcchong avatar Jan 04 '21 21:01 mcchong

Renaming the parent directory might be a temporary workaround, seems to have worked for me just now.

mcchong avatar Jan 04 '21 22:01 mcchong

Try to delete .eslintcache and restart. This is most likely to do with https://github.com/facebook/create-react-app/issues/10161

aaronisrael avatar Jan 06 '21 11:01 aaronisrael

Same issue, need to constantly delete the .eslintcache file otherwise:

  1. Incorrect errors or mising errors displayed
  2. Cached files served

petesmc avatar Jan 15 '21 02:01 petesmc

I'm also seeing this issue on 4.0.1. eslint warnings do not go away after being resolved until I've both deleted .eslintcache and restarted react-scripts start.

gragland avatar Jan 31 '21 01:01 gragland

Same pb here with "react-scripts": "4.0.3" I confirm it looks like a problem with eslintcache

Note that since this version you will need to remove it this way rm node_modules/.cache/.eslintcache

Poyoman39 avatar Mar 11 '21 17:03 Poyoman39

react-scripts 5.0.0. Had that problem with a dependency (file in node_modules). I updated the dependency and the file in node_modules was definitely updated. Removing node_modules/.cache/.eslintcache and restarting the app did not work for me. I removed the entire node_modules folder and installed all packages again, then it worked.

fabpico avatar Feb 23 '22 10:02 fabpico

I'm on react-scripts 5.0.0 and running rm -rf node_modules/.cache/ and then yarn start helped

tomsjansons avatar Feb 25 '22 13:02 tomsjansons

Same issue here. To force the up to date dependencies to be served when deploying dev, we have to remove the entire node_modules/.cache folder before running yarn start

aetherealtech avatar Mar 02 '22 19:03 aetherealtech

I'm on react-scripts 5.0.0 and running rm -rf node_modules/.cache/ and then yarn start helped

same issue with react-scripts-5.0.0 and this worked. Is there a way to make it not use the cache if needed instead of having to manually delete the .cache folder though?

sandilsranasinghe avatar Mar 06 '22 18:03 sandilsranasinghe

I'm on react-scripts 5.0.0 and running rm -rf node_modules/.cache/ and then yarn start helped

This worked finally. My project is also on "react-scripts": "5.0.0",

nwatab avatar Mar 11 '22 23:03 nwatab

Also having this issue on [email protected]

jld-adriano avatar May 04 '22 11:05 jld-adriano

I'm on react-scripts 5.0.0 and running rm -rf node_modules/.cache/ and then yarn start helped

I experienced this too rm -rf node_modules/.cache/ worked for me

karimkawambwa avatar May 04 '22 22:05 karimkawambwa

I'm on react-scripts 5.0.0 and running rm -rf node_modules/.cache/ and then yarn start helped

rm -rf node_modules/.cache/ worked for me thanks

thiago-js avatar Aug 20 '22 20:08 thiago-js

If anyone here is using plugin:@typescript-eslint/recommended-requiring-type-checking there's a known incompatibility: https://github.com/typescript-eslint/typescript-eslint/issues/4694#issuecomment-1075389608

codebutler avatar Sep 13 '22 17:09 codebutler

Add workaround into your package.json

"scripts": {
    "prestart": "rm -rf node_modules/.cache/",
    ...
}

then restart your dev server ^c npm start

ghost avatar Sep 30 '22 09:09 ghost

@pull-task-dev i would not do that if I expect CRA to start quickly. On big projects you have to wait more than one minute when cache has to be generated

Poyoman39 avatar Sep 30 '22 09:09 Poyoman39

Still seeing this when hand-jamming something in node_modules to test a fix quickly. Have to rm -rf node_modules/.cache; npm start to get those changes to be built. We're using CRA v5.0.1 -- any fix?

JoshMcCullough avatar Jan 25 '23 04:01 JoshMcCullough

This is still happening today with the latest release v5.0.1.

fabpico avatar Feb 27 '23 13:02 fabpico

rm -rf node_modules/.cache/ throws error require is not defined

nikoloza avatar Mar 07 '23 04:03 nikoloza

Not specifically 'create-react-app' but I am having the same issue in a 'Svelte'-project and it might be related.

  • Saving file.
  • Refresh web-page.
  • Ctrl + F5 web-page.
  • Re-run 'npm run dev'.
  • 'npm cache clean --force'.
  • 'npm rebuild'.
  • Remove 'node_modules' and re-install.
  • Reboot machine.
  • Create new project in VSC.

These are the steps I've taken to no effect.

p145085 avatar Mar 08 '23 12:03 p145085

Just happened to me. Removing eslint cache didn't work. Removing the whole .cache folder did the job. I'm using version 5.0.1 of React Scripts.

Tiagoperes avatar Mar 17 '23 11:03 Tiagoperes

This seems like a pretty big "oopsie" -- would love to hear some official comment on when it'll be fixed, etc.

JoshMcCullough avatar Mar 27 '23 19:03 JoshMcCullough

"rm -rf node_modules/.cache; npm start" worked for a while and then stopped working for me

leifenberg avatar Apr 10 '23 13:04 leifenberg

"rm -rf node_modules/.cache; npm start" worked for a while and then stopped working for me

  1. Remove module caches

rm -rf node_modules/.cache

  1. Cleaning cache on the browser
const clearCacheData = () => {
  caches.keys().then((names) => {
    names.forEach((name) => {
      caches.delete(name)
    })
  })
  console.log('Complete Cache Cleared')
}
function App () {
  useEffect(() => clearCacheData(), [])

nikoloza avatar Apr 10 '23 14:04 nikoloza

Same issue. Removing node_modules/.cache completely is what solved it for me. Otherwise, I couldn't get relative-deps to work.

ulitol97 avatar Apr 19 '23 16:04 ulitol97

"rm -rf node_modules/.cache; npm start" worked for a while and then stopped working for me

1. Remove module caches

rm -rf node_modules/.cache

2. Cleaning cache on the browser
const clearCacheData = () => {
  caches.keys().then((names) => {
    names.forEach((name) => {
      caches.delete(name)
    })
  })
  console.log('Complete Cache Cleared')
}
function App () {
  useEffect(() => clearCacheData(), [])

removing .cache wasn't working for me on 5.0.1. Removed browser cache and it's working fine now. Thanks

splendidbug avatar May 17 '23 08:05 splendidbug

This error is still happening and removing node_modules/.cache solved it. Any updates on this error? 🤔

gdfbarbosa avatar Jun 23 '23 19:06 gdfbarbosa

+1 for rm -rf node_modules/.cache, was having this issue when trying to use react-scripts build and that command solved it

LivingInLimbo avatar Aug 27 '23 04:08 LivingInLimbo