2

Cannot find module Please verify that the package.json has a valid "main" entry nuxtjs error on npm run dev

FATAL Cannot find module '/root/html/node_modules/iconv-lite/lib/index.js'. Please verify that the package.json has a valid "main" entry

  at tryPackage (node:internal/modules/cjs/loader:353:19)
  at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
  at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
  at Function.resolve (node:internal/modules/cjs/helpers:108:19)
  at p (node_modules/jiti/dist/jiti.js:1:52925)
  at g (node_modules/jiti/dist/jiti.js:1:54200)
  at node_modules/external-editor/main/index.js:12:20
  at g (node_modules/jiti/dist/jiti.js:1:55111)
  at node_modules/inquirer/lib/prompts/editor.js:7:17
  at g (node_modules/jiti/dist/jiti.js:1:55111)
DP Mishra
  • 21
  • 1
  • 2

3 Answers3

3

I got a similar error and fixed it by deleting node_modules and package-lock.json files and then run "npm install" to install dependencies.

dogukan
  • 393
  • 1
  • 4
  • 9
1

Following step should help

  1. Delete the package-lock.json and node_modules
  2. Run npm install
Raphaël Balet
  • 6,334
  • 6
  • 41
  • 78
John
  • 99
  • 2
  • 6
  • Deleting the lock file shouldn't be promoted. It can lead to accidental upgrade of packages and thus can potential break your project. – Leap Hawk Apr 12 '22 at 15:29
  • @LeapHawk I believe you can use "npm install --legacy-peer-deps" to fix any issues on packages. [more on peer dependencies](https://stackoverflow.com/questions/66239691/what-does-npm-install-legacy-peer-deps-do-exactly-when-is-it-recommended-wh) – John Aug 26 '22 at 22:55
  • @LeapHawk If you're afraid to delete the `package-lock.json` you should then fix the version in the `package.json` file, so instead of `^1.0.0` use `1.0.0` and then you can safely remove the `package-lock.json` file, so this answer do make sense – Raphaël Balet Sep 27 '22 at 10:53
0

If you use typescript, you should install ts-node and run build to compile typescript to javascript.

Raminadeeb
  • 29
  • 3