Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm version throws TypeError on 'trim'. #2097

Closed
Johannestegner opened this issue Oct 31, 2020 · 9 comments
Closed

[BUG] npm version throws TypeError on 'trim'. #2097

Johannestegner opened this issue Oct 31, 2020 · 9 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release

Comments

@Johannestegner
Copy link

Current Behavior:

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 npm@7.0.3
2 info using node@v15.0.1
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

Expected Behavior:

The npm package version should be updated to defined version.

Steps To Reproduce:

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

Environment:

OS: Alpine linux
Node: 15.0.1
NPM: 7.0.3

@Johannestegner Johannestegner added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Oct 31, 2020
@ljharb
Copy link
Contributor

ljharb commented Oct 31, 2020

Can you try on npm v7.0.7?

@Johannestegner
Copy link
Author

Johannestegner commented Oct 31, 2020

Will do!


Edit: Takes a couple of more minutes, want to use the same image to be sure it's the same environment :P

@Johannestegner
Copy link
Author

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! :)

@Johannestegner
Copy link
Author

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.

@Johannestegner
Copy link
Author

Just updated my windows host npm and tested another package, it gave the same issue.

@Johannestegner
Copy link
Author

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 :/

@shadowspawn
Copy link
Contributor

shadowspawn commented Nov 1, 2020

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

@Johannestegner
Copy link
Author

Ah tyvm @shadowspawn, that will be easy to fix! :)

@isaacs
Copy link
Contributor

isaacs commented Nov 3, 2020

Going to handle it over on libnpmversion. Thanks for the report! npm/libnpmversion#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

5 participants