ds300 / patch-package

Fix broken node modules instantly šŸƒšŸ½ā€ā™€ļøšŸ’Ø
MIT License
10.26k stars 287 forks source link

TypeError: Cannot read properties of undefined (reading 'dependencies') when trying to run npx patch-package #431

Closed ryaa closed 1 year ago

ryaa commented 1 year ago

I'm getting the below error when trying to run npx patch-package

npx patch-package @capacitor-community/camera-preview
patch-package 6.5.0
ā€¢ Creating temporary folder
TypeError: Cannot read properties of undefined (reading 'dependencies')
    at Object.getPackageResolution (/Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/getPackageResolution.js:89:40)
    at Object.makePatch (/Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/makePatch.js:52:63)
    at /Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/index.js:53:25
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/index.js:52:22)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
/Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/makePatch.js:218
        throw e;
        ^

TypeError: Cannot read properties of undefined (reading 'dependencies')
    at Object.getPackageResolution (/Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/getPackageResolution.js:89:40)
    at Object.makePatch (/Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/makePatch.js:52:63)
    at /Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/index.js:53:25
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/Users/alexryltsov/Git/BOSS811-MOBILE/chore-461-remove-jetifier-package-and-its-usage-in-postinstall-step/node_modules/patch-package/dist/index.js:52:22)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)

Node.js v18.12.0

I saw the similar issue however i have the required package in my package-lock.json file. Please note that i use node 18.12.0 and npm 9.0 (which uses package-lock.json version 3). Could it be the reason for the problem?

ryaa commented 1 year ago

The problem is really caused by lockfile version 3 where the dependencies property does not exist. There is a ticket already added which should handle this problem - see https://github.com/ds300/patch-package/issues/393

orta commented 1 year ago

Cool, closing as dupe of #393

Samuel-Therrien-Beslogic commented 10 months ago

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
CristianFigueredo commented 8 months ago

Update the patch-package to the last version solve my issue :D