'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 1:[1]

I solved this to removing the node_modules folder, package-lock.json file and executing:

npm install

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alberto Manuel