Error: Cannot find module '../../package.json'
Asked Answered
D

3

8

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
Digitigrade answered 9/11, 2021 at 7:58 Comment(0)
L
6

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.

Lalalalage answered 9/11, 2021 at 13:52 Comment(0)
S
5

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

npm install
Spikenard answered 26/2, 2022 at 16:49 Comment(0)
F
1

I've been scratching my head over this for an hour and the answer by @Alberto Manuel helped me find the solution. I, too, cleared the node_modules, package-lock.json and tried npm install but that didn't work.

Then I did npm install --legacy-peer-deps after clearing both the node_modules, package-lock.json. That finally fixed my issue.

Looks like npm install was overriding the legacy versions of dependencies with higher versions or skipping them altogether.

Frosting answered 18/9, 2022 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.