npm not working on windows - Error: Cannot find module 'emoji-regex'

npm not working on windows - Error: Cannot find module 'emoji-regex'

我正在尝试更新 npm 的版本,但我不知道出了什么问题,但从那时起,npm 的任何命令都无法正常工作(全局以及任何文件夹内)。我不能 npm install,甚至 npm -v 我已经尝试卸载和安装节点、更新节点版本、使用以前的版本,但没有任何效果。它给了我以下错误:

 node:internal/modules/cjs/loader:933
  const err = new Error(message);
              ^

Error: Cannot find module 'emoji-regex'
Require stack:
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\node_modules\string-width\index.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\lib\wide-truncate.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\lib\render-template.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\lib\plumbing.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\lib\index.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\npmlog\lib\log.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\lib\utils\log-shim.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\lib\utils\exit-handler.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
←[90m    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:778:27)←[39m
←[90m    at Module.require (node:internal/modules/cjs/loader:1005:19)←[39m
←[90m    at require (node:internal/modules/cjs/helpers:102:18)←[39m
    at Object.<anonymous> (C:\Users\nihal\AppData\Roaming\npm\node_modules\←[4mnpm←[24m\node_modules\←[4mgauge←[24m\node_modules\←[4mstring-width←[24m\index.js:4:20)
←[90m    at Module._compile (node:internal/modules/cjs/loader:1103:14)←[39m
←[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)←[39m
←[90m    at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m    at Module.require (node:internal/modules/cjs/loader:1005:19)←[39m {
  code: ←[32m'MODULE_NOT_FOUND'←[39m,
  requireStack: [
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\node_modules\string-width\index.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\lib\wide-truncate.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\lib\render-template.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\lib\plumbing.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\gauge\lib\index.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\node_modules\npmlog\lib\log.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\lib\utils\log-shim.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\lib\utils\exit-handler.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\lib\cli.js'←[39m,
    ←[32m'C:\Users\nihal\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js'←[39m
  ]
}

我尝试了 where nodewhere npm,他们分别给出了这些结果:

C:\Program Files\nodejs\node.exe 

C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
C:\Users\nihal\AppData\Roaming\npm\npm
C:\Users\nihal\AppData\Roaming\npm\npm.cmd

感谢任何帮助。谢谢!

所以经过多次尝试和错误,我终于能够解决这个问题。这些是我遵循的步骤:

  1. 使用 where nodewhere npm 来了解他们的位置。
  2. 卸载 Nodejs
  3. 手动删除我在步骤 1 中找到的所有文件夹(如果它们仍然存在。对我来说,它们是)。
  4. 安装最新的 Nodejs

现在一切正常。 谢谢!