NPM supports changing and even replacing (transitive) dependencies via the "overrides" node in the package.json, this is a NPM feature since v8 (not sure since when exactly):
I now have this interesting example where I want to replace a (transitive) dependency with a different dependency (not only a different version) in order to get rid of bugs/in order to increase build-speed/because the lib got reworked under different package coordinates:
After npm install all dependencies are getting downloaded, but as magic-string and nano-css are now sharing the same version, the node_modules-folder contain a symlink to the real package. Having two dependencies sharing the same version of a transitive dependency is KEY to this bug. Having only magic-string does not recreate the problem.
Here a tree-output of the magic-string in node_modules:
After download is finished I need to adjust the magic-string-package to reflect the new @jridgewell/sourcemap-codec coordinates, so I edit the files node_modules/magic-string/dist/magic-string.cjs.js and node_modules/magic-string/dist/magic-string.es.js.
Now here comes the problem: when I run npx patch-package magic-string after my edits, to create a patch-file (as normal), I will get greeted with a weird warning:
(Text version of the screenshot, to improve searchability)
patch-package 6.5.1
• Creating temporary folder
• Installing magic-string@0.25.9 with npm
• Diffing your files with clean files
Error: ENOENT: no such file or directory, stat 'C:\develop\tmp\some-patch-package-thing\node_modules\magic-string\node_modules\sourcemap-codec'
at Object.statSync (node:fs:1596:3)
at Object.statSync (C:\develop\tmp\some-patch-package-thing\node_modules\graceful-fs\polyfills.js:318:34)
at statSync (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\util\stat.js:10:52)
at getStatsSync (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\util\stat.js:24:19)
at Object.checkPathsSync (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\util\stat.js:49:33)
at copyDirItem (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\copy-sync\copy-sync.js:121:29)
at C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\copy-sync\copy-sync.js:115:39
at Array.forEach (<anonymous>)
at copyDir (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\copy-sync\copy-sync.js:115:23)
at mkDirAndCopy (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\copy-sync\copy-sync.js:110:3) {
errno: -4058,
syscall: 'stat',
code: 'ENOENT',
path: 'C:\\develop\\tmp\\some-patch-package-thing\\node_modules\\magic-string\\node_modules\\sourcemap-codec'
}
C:\develop\tmp\some-patch-package-thing\node_modules\patch-package\dist\makePatch.js:218
throw e;
^
This probably is due to the node_modules folder not existing in the one which gets downloaded on the • Installing magic-string@0.25.9 with npm step. I have not tested this on MacOS or Linux systems.
Not sure if bug or (not yet implemented) feature.
NPM supports changing and even replacing (transitive) dependencies via the
"overrides"
node in thepackage.json
, this is a NPM feature since v8 (not sure since when exactly):I now have this interesting example where I want to replace a (transitive) dependency with a different dependency (not only a different version) in order to get rid of bugs/in order to increase build-speed/because the lib got reworked under different package coordinates:
After
npm install
all dependencies are getting downloaded, but asmagic-string
andnano-css
are now sharing the same version, thenode_modules
-folder contain a symlink to the real package. Having two dependencies sharing the same version of a transitive dependency is KEY to this bug. Having onlymagic-string
does not recreate the problem.Here a
tree
-output of themagic-string
innode_modules
:After download is finished I need to adjust the
magic-string
-package to reflect the new@jridgewell/sourcemap-codec
coordinates, so I edit the filesnode_modules/magic-string/dist/magic-string.cjs.js
andnode_modules/magic-string/dist/magic-string.es.js
.Now here comes the problem: when I run![grafik](https://user-images.githubusercontent.com/1042579/220422208-f40b01cc-1919-48a6-9f20-5a587b9e4e95.png)
npx patch-package magic-string
after my edits, to create a patch-file (as normal), I will get greeted with a weird warning:(Text version of the screenshot, to improve searchability)
This probably is due to the
node_modules
folder not existing in the one which gets downloaded on the• Installing magic-string@0.25.9 with npm
step. I have not tested this on MacOS or Linux systems.OS: Windows 10 Pro Node: v18.14.0 NPM: 9.4.2