'Node.js: Cannot find module 'immer'

The Problem

In this error, I cannot run npm start. Shown below are my scripts in package.json.

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "server": "nodemon server.js",
    "client": "npm run start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },

What I tried

I saw this and this from another stackoverflow post but it's not the same case for me.

I tried to do npm install and update npm itself. Before I encountered the error, I was installing and uninstalling npm packages so I reset to my old commit because maybe the changes in the package.json caused the error. Upon doing this, I still have the same error. Any ideas to fix this? Thanks!

Here is the error log:

node:internal/modules/cjs/loader:928
  throw err;
  ^

Error: Cannot find module 'immer'
Require stack:
- /Users/username/Documents/path/to/project/node_modules/react-dev-utils/immer.js
- /Users/username/Documents/path/to/project/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js
- /Users/username/Documents/path/to/project/node_modules/react-scripts/scripts/start.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/username/Documents/path/to/project/node_modules/react-dev-utils/immer.js:10:13)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:997:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/username/Documents/path/to/project/node_modules/react-dev-utils/immer.js',
    '/Users/username/Documents/path/to/project/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js',
    '/Users/username/Documents/path/to/project/node_modules/react-scripts/scripts/start.js'
  ]
}


Solution 1:[1]

Try installing the package with:

npm i immer

https://www.npmjs.com/package/immer

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 r_a_zeyad