Seemingly out of nowhere, our React app (using Create React App) cannot be built anymore. It fails to load a Babel module:
$ yarn build
yarn run v1.22.19
$ react-scripts build
node:internal/modules/cjs/loader:371
throw err;
^
Error: Cannot find module 'C:\dev\node_modules\@babel\types\lib\index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (node:internal/modules/cjs/loader:363:19)
at Module._findPath (node:internal/modules/cjs/loader:576:18)
at Module._resolveFilename (node:internal/modules/cjs/loader:941:27)
at Module._load (node:internal/modules/cjs/loader:803:27)
at Module.require (node:internal/modules/cjs/loader:1021:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (C:\dev\node_modules\@babel\helper-module-imports\lib\import-injector.js:10:9)
at Module._compile (node:internal/modules/cjs/loader:1119:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
at Module.load (node:internal/modules/cjs/loader:997:32) {
code: 'MODULE_NOT_FOUND',
path: 'C:\\dev\\node_modules\\@babel\\types\\package.json',
requestPath: '@babel/types'
}
Indeed, after yarn install, there is no lib folder inside node_modules\@babel\types\.
The potentially relevant parts of the package.json:
{
// ...
"dependencies": {
"@babel/runtime": "~7.15.3",
"core-js": "~3.16.2",
"platform": "~1.3.6",
"prop-types": "~15.7.2",
"react": "~17.0.2",
"react-app-polyfill": "2.0.0",
"react-dom": "~17.0.2",
"regenerator-runtime": "~0.13.9"
// ...
},
"devDependencies": {
"react-scripts": "4.0.3",
"typescript": "4.3.5"
// ...
},
"scripts": {
"build": "react-scripts build"
// ...
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
My current environment is:
- Windows 10 Pro 19043.1889
- Node.js 18.8.0
- yarn 1.22.19
An update to @babel/runtime@7.18.9 did not help.
I think the action that may have broken the build on my machine is npx browserslist@latest --update-db, which I was requested to run by a previous build. I do not see the connection though.
After the problem occured, I tried multiple things, so I am not sure in exactly which environment things still worked. It must have been:
- Node.js 16.x.x
- yarn >= 1.21.1
Any ideas?