Open Bow2Jesus opened 1 year ago
That appears to be an invalid overrides
section. The syntax for overrides requires a proper package spec, not a $
prefixed string.
The $prefix is right from the NPM package documentation: https://docs.npmjs.com/cli/v8/configuring-npm/package-json/
I also ran into this issue on the npm/documentation
. Currently the install fails with the same message on 9.1.1
but works on 8.19.3
.
{
"name": "npm-documentation",
"repository": "npm/documentation",
"version": "0.1.0",
"private": true,
"scripts": {
"develop": "gatsby develop",
"build": "NODE_OPTIONS=--max-old-space-size=5376 gatsby build",
"serve": "gatsby serve"
},
"workspaces": [
"cli/",
"theme/"
],
"dependencies": {
"gatsby": "^4.24.4",
"gatsby-plugin-meta-redirect": "^1.1.1",
"theme": "*",
"react": "^16.14.0",
"react-dom": "^16.14.0"
},
"overrides": {
"react": "$react"
},
"templateOSS": {
"rootRepo": false,
"rootModule": false,
"workspaces": [
"cli"
],
"version": "4.6.2"
}
}
I have this bug too and I can reproduce it quickly with node v18.12.0
and npm v9.1.2
with this package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@storybook/csf": "next"
},
"overrides": {
"@storybook/csf": "next"
}
}
And after downgrading to npm@8.19.3
it works as expected.
What I noticed is the problem comes when the version is using a tag instead of a version, for example
This fails ❌
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@storybook/csf": "next"
},
"overrides": {
"@storybook/csf": "$@storybook/csf"
}
}
This works ✅
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@storybook/csf": "^0.0.2-next.7"
},
"overrides": {
"@storybook/csf": "$@storybook/csf"
}
}
This is still a problem on v9.2.0
:(
I see the same problem w/ 8.19.3
Just went into the same bug with 9.3.1
.
The following doesn't work,
{
// ...
"dependencies": {
"@babel/core": "^7.20.12"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
},
"overrides": {
"@trivago/prettier-plugin-sort-imports": {
"@babel/core": "$@babel/core",
"@babel/parser": "$@babel/core",
"@babel/traverse": "$@babel/core"
}
}
}
But this do work,
{
// Same as above
"overrides": {
"@trivago/prettier-plugin-sort-imports": {
"@babel/core": "^7.20.12",
"@babel/parser": "$@babel/core",
"@babel/traverse": "$@babel/core"
}
}
}
I had the same issue with npm versions 9.2.0
and 9.6.1
and managed to work around it by changing all self-referencing overrides (like react: "$react"
) to use the version number specified in "dependencies"
, running npm i
to re-generate the package-lock.json
file (after deleting it -- though not sure if that was necessary) and then I could change back to react: "$react"
and no longer received the error
e.g. change
...
"overrides": {
"react-native": {
"react": "$react"
},
"craco-less": {
"react": "$react",
"react-dom": "$react",
"@craco/craco": "$@craco/craco"
}
}
...
to
...
"overrides": {
"react-native": {
"react": "^17.0.2"
},
"craco-less": {
"react": "^17.0.2",
"react-dom": "$react",
"@craco/craco": "$@craco/craco"
}
}
...
re-generate the package-lock.json
, and then change the package.json
back again
Hopefully helps someone debug the issue or at least work around it for now
Also, this seems like a re-occurrence of #4395 which is marked as closed but seems to still be present in npm 9.6.1
We were running into this weird behaviour with certain $<package name>
references in overrides
being unrecognised under the following circumstances:
--legacy-peer-deps
(via the cli or config, or perhaps just NPM version <= 6) had previously been (re)used to touch the package-lock.json
"debug": true
were marked on packages that would not have them normally with a plain npm install
The solution to fixing this was:
--legacy-peer-deps
, or NPM version <= 6, to update package-lock.json
overrides
to use explicit version matching to update package-lock.json
(this could end up removing "debug": true
s)overrides
to $<package name>
version references and update the package-lock.json
– as highlighted by @callumnewlands aboveIf this issue pops up again in a repo, it is probably because someone used --legacy-peer-deps
to update the package-lock.json
.
Just as an additional point of reference, I can reproduce this issue without node_modules
and package-lock.json
, so this might actually be a combination of several different issues.
I have an example that fails with npm 9.6.2:
{
"name": "override",
"dependencies": {
"ts-jest": "^29.0.5",
"typescript": "^5.0.2"
},
"overrides": {
"typescript": "$typescript"
}
}
Without ts-jest it works.
Might be related - ts-jest has peerDependency: "typescript": ">=4.3"
Temporary solution I've found is to delete the override, install, then add back the override, then install again.
If this issue pops up again in a repo, it is probably because someone used
--legacy-peer-deps
to update thepackage-lock.json
.
We faced this again with correct package-lock.json
and only solution for us was to replace references in overrides to use same versions than the ones in dependencies/devDependencies/peerDependencies
using node v18.15.0 (npm v9.5.0)
When another top level dependency requires the overridden dependency and is resolved before the overridden one, the reference has not been created yet.
{
"name": "example",
"dependencies": {
"foo": "^4.2.0",
"bar": "^1.0.0",
},
"overrides": {
"foo": "$foo"
}
}
{
"name": "bar",
"dependencies": {
"foo": "^3.2.0",
}
}
The order in which the packages are resolved determines whether this works or not.
Since npm-update
doesn't work on overrides
it requires constant manual maintenance and this feature, in its current state, is therefore de facto worthless.
Ran into the same issue. I deleted package-lock.json and node_modules and reinstalled everything via npm install
I have had the same problem with $react-native
npm ERR! Unable to resolve reference $react-native
I just took the suggestion from above and replaced the $react-native variable with the version defined in the devDependencies and it worked fine.
... Since
npm-update
doesn't work onoverrides
it requires constant manual maintenance and this feature, in its current state, is therefore de facto worthless.
The problem of updating dependencies can be solved using npm-check-updates
. In v16.14.2 https://github.com/raineorshine/npm-check-updates/issues/1332#issuecomment-1717862332 it updates overrides
as well.
@Bow2Jesus Can you add the tags for NPM 10? That will make it clear for everybody that the issue is still applicable to the current release.
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
I am attempting to run npm install to create the node_modules folder with nodes and package-lock.json file from the package.json file. When I run npm install it returns this error message "npm ERR! Unable to resolve reference $react".
Expected Behavior
Since I have react and its version defined in my dependencies, then I expect npm to resolve the reference to react and finish processing my package.json file.
Steps To Reproduce
Environment
prefix = "C:\Users\i338909\AppData\Roaming\npm"
; "user" config from C:\Users\i338909.npmrc
http_proxy = "http://bcproxy.hcscint.net:8080" https_proxy = "http://bcproxy.hcscint.net:8080" proxy = "http://bcproxy.hcscint.net:8080/" registry = "http://nexus.fyiblue.com/repository/npm-all/" scripts-prepend-node-path = true strict-ssl = true
; node bin location = C:\Program Files\nodejs\node.exe ; node version = v16.18.0 ; npm local prefix = C:\NMP_TEST\rover-web-app-test ; npm version = 8.19.2 ; cwd = C:\NMP_TEST\rover-web-app-test ; HOME = C:\Users\i338909 ; Run
npm config ls -l
to show all defaults.