nodejs: 未满足的依赖 type@module / 如何让 `npm list` 不再返回此错误?

huangapple go评论60阅读模式
英文:

nodejs: UNMET DEPENDENCY type@module / How can I get `npm list` stop returning this error?

问题

D:\TEMP\nodejs\count>npm list
TEMP@ D:\TEMP
+-- file-type@17.1.1
+-- html2pdf.js@0.10.1
+-- html2pdf@0.0.11
+-- mysql@2.18.1
+-- sqlite3@5.0.3
`-- UNMET DEPENDENCY type@module

npm ERR! code ELSPROBLEMS
npm ERR! missing: type@module, required by TEMP@

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Luuk\AppData\Local\npm-cache\_logs23-01-07T17_11_04_588Z-debug-0.log
  • The logfile is of no help (to me)
  • I did search using Google, but that was not leading to a solution.

I removed nodejs from my computer, then re-installed it. This is giving the exact same error.

For re-installing I used node-v18.12.1-x64.msi

EDIT: Installing using node-v18.13.0-x64.msi gives the same problems.

How can I get npm list to stop returning this error?

BTW: The directory D:\TEMP\nodejs\count is an empty directory on My Windows 11 system.

BTW: The word error is mentioned here in that log file:

D:\TEMP\nodejs\count>findstr /i error "C:\Users\Luuk\AppData\Local\npm-cache\_logs23-01-07T17_11_04_588Z-debug-0.log"

38 verbose stack Error: missing: type@module, required by TEMP@
43 error code ELSPROBLEMS
44 error missing: type@module, required by TEMP@
48 error A complete log of this run can be found in:
48 error C:\Users\Luuk\AppData\Local\npm-cache\_logs23-01-07T17_11_04_588Z-debug-0.log

EDIT:

  • After removing the node_modules directory (move node_modules node_modules.1), in the directory C:\Program Files\nodejs
  • I did npm cache clean which produced:
D:\TEMP\nodejs\count>npm cache clean
node:internal/modules/cjs/loader:1042
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.13.0
node:internal/modules/cjs/loader:1042
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.13.0
英文:
D:\TEMP\nodejs\count>npm list
TEMP@ D:\TEMP
+-- file-type@17.1.1
+-- html2pdf.js@0.10.1
+-- html2pdf@0.0.11
+-- mysql@2.18.1
+-- sqlite3@5.0.3
`-- UNMET DEPENDENCY type@module

npm ERR! code ELSPROBLEMS
npm ERR! missing: type@module, required by TEMP@

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Luuk\AppData\Local\npm-cache\_logs23-01-07T17_11_04_588Z-debug-0.log
  • The logfile is of no help (to me)
  • I did search using Google, but that was not leading to a solution.

I removed nodejs from my computer, then re-installed it This is giving the exact same error.

For re-installing I used node-v18.12.1-x64.msi

EDIT: Installing using node-v18.13.0-x64.msi gives same problems.

How can I get npm list stop returning this error?

BTW: The directory D:\TEMP\nodejs\count is an empty directory on My Windows 11 system.

BTW: The word error is mentioned here in that log file:

D:\TEMP\nodejs\count>findstr /i error "C:\Users\Luuk\AppData\Local\npm-cache\_logs23-01-07T17_11_04_588Z-debug-0.log"

38 verbose stack Error: missing: type@module, required by TEMP@
43 error code ELSPROBLEMS
44 error missing: type@module, required by TEMP@
48 error A complete log of this run can be found in:
48 error     C:\Users\Luuk\AppData\Local\npm-cache\_logs23-01-07T17_11_04_588Z-debug-0.log

EDIT:

  • After removing the node_modules directory (move node_modules node_modules.1, in the directory C:\Program Files\nodejs )
  • I did npm cache clean which produced:
D:\TEMP\nodejs\count>npm cache clean
node:internal/modules/cjs/loader:1042
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.13.0
node:internal/modules/cjs/loader:1042
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.13.0

答案1

得分: 0

NPM的依赖解析器似乎有些问题,因此不能完全信任NPM的安全建议和工具,如NPM审计和NPM列表。阅读这个 - https://github.com/npm/npm/issues/1341#issuecomment-20634338

这里是解决该问题的快速方法 -

步骤1 - 删除node_modules目录

步骤2 - 运行 npm cache clean

步骤3 - 运行 npm install

英文:

NPM's dependency resolver seems to be broken a bit due to which NPM's security suggestions and tools such as NPM audit, NPM list cannot be trusted fully. Read this - https://github.com/npm/npm/issues/1341#issuecomment-20634338

Here a quick fix for the issue that may help -

Step 1 - Remove node_modules directory

Step 2 - Run npm cache clean

Step 3 - Run npm install

答案2

得分: 0

看起来我需要使用npm init创建一个(空的)应用程序,这将创建一个名为"package.json"的文件,其中包含以下内容(当要求输入名称时,我输入了"test",然后在其他问题上只是按了回车键):

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

之后:

D:\TEMP\npm>npm list
test@1.0.0 D:\TEMP\npm
`-- (empty)
D:\TEMP\npm>npm update

up to date, audited 1 package in 72ms

found 0 vulnerabilities
英文:

It seems that i need to create a (emtpy) application using npm init, which will create a file name "package.json", which has the following contents (I entered "test", whan a name was asked, and just hit the enter button on the rest of the questions):

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

After this:

D:\TEMP\npm>npm list
test@1.0.0 D:\TEMP\npm
`-- (empty)
D:\TEMP\npm>npm update

up to date, audited 1 package in 72ms

found 0 vulnerabilities

huangapple
  • 本文由 发表于 2023年1月8日 01:16:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75042292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定