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

TypeError: Cannot read properties of undefined (reading 'dependencies') #437

Closed
curious-george-nine opened this issue Dec 9, 2022 · 9 comments

Comments

@curious-george-nine
Copy link

curious-george-nine commented Dec 9, 2022

I tried to use this in my project. then it says an error.
using npm

patch-package 6.5.0
• Creating temporary folder
TypeError: Cannot read properties of undefined (reading 'dependencies')
    at Object.getPackageResolution (path\to\node_modules\patch-package\dist\getPackageResolution.js:89:40)
    at Object.makePatch (path\to\node_modules\patch-package\dist\makePatch.js:52:63)
    at path\to\node_modules\patch-package\dist\index.js:53:25
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (path\to\node_modules\patch-package\dist\index.js:52:22)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
path\to\node_modules\patch-package\dist\makePatch.js:218
        throw e;
        ^

TypeError: Cannot read properties of undefined (reading 'dependencies')
    at Object.getPackageResolution (path\to\node_modules\patch-package\dist\getPackageResolution.js:89:40)
    at Object.makePatch (path\to\node_modules\patch-package\dist\makePatch.js:52:63)
    at path\to\node_modules\patch-package\dist\index.js:53:25
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (path\to\node_modules\patch-package\dist\index.js:52:22)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
@zqianem
Copy link

zqianem commented Dec 10, 2022

This is likely due to using a lockfileVersion of 3 (produces the same stack trace) and will be fixed by #434.

@alekseyBatuhtin
Copy link

I solved the problem in this way

  1. converted package-lock to version=2
  2. npx patch-package your-package
  3. return back package-lock to version=3

@el-j
Copy link

el-j commented Dec 22, 2022

  1. convert your lockfile to version 2
npm shrinkwrap --lockfile-version 2
  1. edit 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);
  1. use patch-package to create a patch:
npx patch-package react-script
  1. package.json change build and add build-dev + postinstall patch
"scripts": {
...
"build": "NODE_ENV=production react-scripts build",
"build-dev": "NODE_ENV=development react-scripts build",
"postinstall": "npx patch-package"
...
},
  1. create lockfile version 3
npm shrinkwrap --lockfile-version 3
  1. rename shrinkwrap.json to package-lock.json

thanks for the idea @alekseyBatuhtin @zqianem

@tobua
Copy link

tobua commented Dec 25, 2022

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.

@acoreyj
Copy link

acoreyj commented Dec 30, 2022

Anyone tried to use patch-package to patch patch-package so you can run patch-package?

@tobua
Copy link

tobua commented Jan 4, 2023

Update has been released in 6.5.1 and is working fine, thanks!

@ds300 ds300 closed this as completed Jan 4, 2023
@DovletAmanov
Copy link

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.

@Samuel-Therrien-Beslogic

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

@vision-llz
Copy link

就我而言,我意识到我的项目中同时存在package-lockyarn.lock。我主要使用纱线,所以删除后package-lock错误就消失了。

good idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants