Closed curious-george-nine closed 1 year ago
This is likely due to using a lockfileVersion
of 3
(produces the same stack trace) and will be fixed by https://github.com/ds300/patch-package/pull/434.
I solved the problem in this way
npm shrinkwrap --lockfile-version 2
node_modules/react-scripts/scripts/build.js
and change line 12 | 13
+ 58
:
// process.env.BABEL_ENV = "production"
// process.env.NODE_ENV = "production"
process.env.BABEL_ENV = process.env.NODE_ENV
process.env.NODE_ENV = process.env.NODE_ENV
// const config = configFactory("production"); const config = configFactory(process.env.NODE_ENV);
3. use patch-package to create a patch:
npx patch-package react-script
4. **package.json** change `build` and add `build-dev` + `postinstall` patch
```json
"scripts": {
...
"build": "NODE_ENV=production react-scripts build",
"build-dev": "NODE_ENV=development react-scripts build",
"postinstall": "npx patch-package"
...
},
npm shrinkwrap --lockfile-version 3
shrinkwrap.json
to package-lock.json
thanks for the idea @alekseyBatuhtin @zqianem
Issue happens with npm 9.2.0, which is currently bundled with the latest stable node version. Installing node LTS with npm 8.19.2, removing the lockfile and generating a new one, can also be used as a workaround until #434 lands.
Anyone tried to use patch-package to patch patch-package so you can run patch-package?
In my case I realized that somehow there are both package-lock
and yarn.lock
in my project. I use yarn mainly so after deleting package-lock
error gone.
This is happening to me with patch-package 7.0.0
and patch-package 8.0.0
on Node.js v18.14.0
with a "lockfileVersion": 3
:
npx patch-package localForage
patch-package 8.0.0
• Creating temporary folder
TypeError: Cannot read properties of undefined (reading 'dependencies')
at Object.getPackageResolution (...\node_modules\patch-package\dist\getPackageResolution.js:98:40)
at Object.makePatch (...\node_modules\patch-package\dist\makePatch.js:103:63)
at ...\node_modules\patch-package\dist\index.js:72:25
at Array.forEach (<anonymous>)
at Object.<anonymous> (...\node_modules\patch-package\dist\index.js:71:22)
at Module._compile (node:internal/modules/cjs/loader:1226:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at Module.load (node:internal/modules/cjs/loader:1089:32)
at Module._load (node:internal/modules/cjs/loader:930:12)
at Module.require (node:internal/modules/cjs/loader:1113:19)
...\node_modules\patch-package\dist\makePatch.js:395
throw e;
^
TypeError: Cannot read properties of undefined (reading 'dependencies')
at Object.getPackageResolution (...\node_modules\patch-package\dist\getPackageResolution.js:98:40)
at Object.makePatch (...\node_modules\patch-package\dist\makePatch.js:103:63)
at ...\node_modules\patch-package\dist\index.js:72:25
at Array.forEach (<anonymous>)
at Object.<anonymous> (...\node_modules\patch-package\dist\index.js:71:22)
at Module._compile (node:internal/modules/cjs/loader:1226:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at Module.load (node:internal/modules/cjs/loader:1089:32)
at Module._load (node:internal/modules/cjs/loader:930:12)
at Module.require (node:internal/modules/cjs/loader:1113:19)
Node.js v18.14.0
就我而言,我意识到我的项目中同时存在
package-lock
和yarn.lock
。我主要使用纱线,所以删除后package-lock
错误就消失了。
good idea
I tried to use this in my project. then it says an error. using npm