Skip to content

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

Closed

Description

@Johannestegner

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

Activity

  1. added
    Bug
    Needs Triage
    Release 7.x
    on Oct 31, 2020
  2. ljharb commented on Oct 31, 2020

    @ljharb
    Contributor

    Can you try on npm v7.0.7?

  3. Johannestegner commented on Oct 31, 2020

    @Johannestegner
    Author

    Will do!


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

  4. Johannestegner commented on Oct 31, 2020

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

  5. Johannestegner commented on Oct 31, 2020

    @Johannestegner
    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.

  6. Johannestegner commented on Oct 31, 2020

    @Johannestegner
    Author

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

  7. Johannestegner commented on Oct 31, 2020

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

  8. shadowspawn commented on Nov 1, 2020

    @shadowspawn
    Contributor

    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

  9. Johannestegner commented on Nov 1, 2020

    @Johannestegner
    Author

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

  10. isaacs commented on Nov 3, 2020

    @isaacs
    Contributor

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

  11. reopened this on Nov 6, 2020
  12. added a commit that references this issue on Nov 6, 2020
    e090d70
  13. added this to the OSS - Sprint 19 milestone on Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageRelease 7.x

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions