Search code examples
node.jsdependenciesnode-modulesglobalpackage.json

Error: Cannot find module '../../package.json'


So, I've seen other similar issues. There are a lot, but I can't seem to find a solution for this.

I've already deleted node_modules folder and package-lock.json file from /{username} , where my package.json file is. However, every time I install something globally, it does not update the package.json file, but does install it in /usr/local/lib/node_modules.

This happens every time I run ncu.

Any ideas?

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '../../package.json'
Require stack:
- /usr/local/lib/node_modules/npm-check-updates/build/src/bin/cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm-check-updates/build/src/bin/cli.js:11:40)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/local/lib/node_modules/npm-check-updates/build/src/bin/cli.js'
  ]
}

Node.js v17.0.1

Solution

  • I have just experienced the same. I think it's a bug in the latest version of NCU (12.0.1, released 5 hours ago at the time of writing).

    If I run

    npm install [email protected] -g
    

    then ncu runs fine.

    If I run

    npm install [email protected] -g
    

    then it barfs with this error.

    I just checked the Github page and found that the issue has already been raised as https://github.com/raineorshine/npm-check-updates/issues/990.

    So I guess, follow that issue for any other workarounds and the eventual fix.