When executing npm version {version}
or even npm version from-git
in my CI pipeline I get the following error:
0 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'version', 'from-git' ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 2ms
4 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 3ms
7 timing config:load:env Completed in 2ms
8 timing config:load:file:/builds/open-source/javascript/eslint-config/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/root/.npmrc Completed in 2ms
11 timing config:load:user Completed in 2ms
12 timing config:load:file:/registry.npmjs.org/:_authToken=xxxx
python=/usr/bin/python3 Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 1ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 15ms
19 verbose npm-session xxxx
20 timing npm:load Completed in 26ms
21 timing command:version Completed in 24ms
22 verbose stack TypeError: Cannot read property 'trim' of undefined
22 verbose stack at clean (/usr/local/lib/node_modules/npm/node_modules/semver/functions/clean.js:3:27)
22 verbose stack at module.exports (/usr/local/lib/node_modules/npm/node_modules/libnpmversion/lib/version.js:38:24)
22 verbose stack at module.exports (/usr/local/lib/node_modules/npm/node_modules/libnpmversion/lib/index.js:23:10)
22 verbose stack at async version (/usr/local/lib/node_modules/npm/lib/version.js:40:21)
23 verbose cwd /builds/open-source/javascript/eslint-config
24 verbose Linux 5.4.0-37-generic
25 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "version" "from-git"
26 verbose node v15.0.1
27 verbose npm v7.0.3
28 error Cannot read property 'trim' of undefined
29 verbose exit 1
The npm package version should be updated to defined version.
I use the following docker image (which is built from my ci as well): https://github.com/orgs/jitesoft/packages/container/package/node
The following package is the latest I tried to build: https://github.com/jitesoft/eslint-config
OS: Alpine linux
Node: 15.0.1
NPM: 7.0.3
Can you try on npm v7.0.7?
Will do!
Edit: Takes a couple of more minutes, want to use the same image to be sure it's the same environment :P
Alright, finally got it up and running with the correct version of npm. Still the same issue though.
I find it odd that I experience this, due to the fact that I'm quite sure that thousands of people do this every day, and I don't use any odd commands really.
If you can't reproduce it, let me know and I'll set up a small reproducible case for you! :)
Easiest way to test it is:
docker run --rm -i -t ghcr.io/jitesoft/node:latest /bin/ash
git clone https://github.com/jitesoft/eslint-config.git
cd eslint-config/
npm version 1.2.3
Node is built from source and if you wish to see the build procedure it can be found here:
https://github.com/jitesoft/docker-node-base/blob/master/.gitlab-ci.yml#L115
Just let me know if you need any more info or anything else.
Just updated my windows host npm and tested another package, it gave the same issue.
I must say that this a huge issue, as I have about 20 packages which are deployed quite often (weekly auto, and more often manually), each of which uses the same CI pipeline, and without the availability of the version command, they are all broken.
I guess I could change the base pipeline to use sed or similar to change the version, but one would expect the command to work as intended :/
I reproduced locally on Mac with your repo. I noticed the package.json
in your example repository does not have a version field. Adding one eliminates the error, so that may be a potential work-around.
The package.json
documentation says:
If you plan to publish your package, the _most_ important things in your package.json are the name and version fields as they will be required.
https://docs.npmjs.com/cli/v6/configuring-npm/package-json#version
Ah tyvm @shadowspawn, that will be easy to fix! :)
Going to handle it over on libnpmversion. Thanks for the report! https://github.com/npm/libnpmversion/issues/4
Most helpful comment
I reproduced locally on Mac with your repo. I noticed the
package.json
in your example repository does not have a version field. Adding one eliminates the error, so that may be a potential work-around.The
package.json
documentation says:https://docs.npmjs.com/cli/v6/configuring-npm/package-json#version