“Cannot read property 'match' of undefined” during Npm install

前端 未结 5 1023
北荒
北荒 2020-12-06 09:28

I encountered error during building Jenkins

Jenkins Log

Task :api:processResources Task :api:classes Task :web:node

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 10:11

    I had the same error when running npm install in my repo. I don't use Jenkins, but I found a generic approach to debugging (and ultimately resolving) this issue in NPM.

    1. Open the npm debug log file that the cli provides you. (on Windows, under C:\Users\USERNAME\AppData\Roaming\npm-cache\_logs by default)
    2. Look for the stack trace of the error, at the bottom of the file.
    3. The first three lines of the error stack trace should be something like:
    18 verbose stack TypeError: Cannot read property 'match' of undefined
    18 verbose stack     at tarballToVersion (C:\Users\USERNAME\AppData\Roaming\nvm\v14.5.0\node_modules\npm\lib\install\inflate-shrinkwrap.js:87:20)
    18 verbose stack     at inflatableChild (C:\Users\USERNAME\AppData\Roaming\nvm\v14.5.0\node_modules\npm\lib\install\inflate-shrinkwrap.js:113:22)
    
    1. Open up the inflate-shrinkwrap.js file, and go to the line listed in stack-trace line #3 above.
    2. Add this debugging code: (just before the line [in stack-trace] which calls tarballToVersion)
    if (sw.version == null) {
        console.error(`
            NPM is trying to retrieve package "${name}" with version "undefined"!
            Package location: ${(onDiskChild || {}).location}
            Package parse error:`, (onDiskChild || {}).error);
    }
    
    1. Run npm install (or whatever command yields the error). You should see an output like this:
            NPM is trying to retrieve package with version "undefined"!
            Package location: /firebase-feedback/webpack-dev-middleware
            Package parse error: [Error: ENOENT: no such file or directory, open 'C:\Root\Apps\@V\@Modules\firebase-feedback\Main\node_modules\webpack-dev-middleware\package.json'] {
      errno: -4058,
      code: 'ENOENT',
      syscall: 'open',
      path: 'C:\\Root\\Apps\\@V\\@Modules\\firebase-feedback\\Main\\node_modules\\webpack-dev-middleware\\package.json'
    }
    
    1. Go to the path specified in the internal error. You should find that the package.json file at that path is indeed missing.
    2. Resolve that underlying "package.json" issue as you see fit. (for me, this was by deleting the C:/Root/Apps/@V/@Modules/firebase-feedback/Main/node_modules folder, then running npm install in the Main folder)

    Note that in my case, the underlying issue (of the missing package.json file) appears to have been caused by me accidentally running npm install from the parent project (which uses my firebase-feedback library), while I had that library "npm linked".

    I normally use npm-safe-install to avoid these sorts of issues (when using npm link), but I must have forgotten sometime recently -- leading to NPM mangling the npm-linked libraries' node_modules folders.

    Similar issues relating to npm link have happened before, but I hoped NPM would have patched these sorts of issues by now. Apparently not; though version 7 of NPM has been stated as going to have a rewrite in that area, so hopefully that will solve it long term.

提交回复
热议问题