'npm: Replacing one package from dependencies with a fork (possibly using git)
I'm using terser, which requires esprima. Esprima has been abandoned, so I'd like to replace it with the fork esprima-next. However, no method which I've used to do this has been successful.
Attempt 1:
"devDependencies": {
"esprima": "npm:esprima-next"
},
This installs without error, but the contents in node_modules/esprima are unchanged.
Attempt 2:
"devDependencies": {
"esprima": "github:node-projects/esprima-next"
},
This results in the following:
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://[email protected]/node-projects/esprima-next.git
npm ERR! ssh -oStrictHostKeyChecking=accept-new: line 1: ssh: not found
npm ERR! fatal: Could not read from remote repository.
Attempt 3:
"devDependencies": {
"esprima": "git+https://github.com/node-projects/esprima-next.git"
},
This results in the same error as the second attempt.
How can I replace one dependency with a fork?
Update 1:
I found that I can install esprima-next under the esprima name and directory by pointing to the tarball for esprima-next.
npm show esprima-next
... get the tarball URL from the output
npm install --save esprima@https://registry.npmjs.org/esprima-next/-/esprima-next-5.8.1.tgz
This works, in that node_modules/esprima/ contains the right code. However, packages like requirejs and terser seem to bundle esprima in their own code, and so I still can't get them to use esprima-next.
Solution 1:[1]
Try using resolutions in your package.json.
devDependencies: {
terser: ^5.0.0,
....
},
resolutions: {
"esprima": "git+https://github.com/node-projects/esprima-next.git"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Satya S |
