节点“错误:找不到模块“节点:进程””使用全局 fastify-cli (mac) 时

发布于 2025-01-11 10:02:15 字数 2436 浏览 0 评论 0原文

我正在设置一台新的 mac 开发机器,并安装了 node、npm 和 nvm。在单个项目目录中一切看起来都很好。但是,当尝试安装和使用 fastify-cli 时,我收到错误:

internal/modules/cjs/loader.js:892
  throw err;
  ^

Error: Cannot find module 'node:process'
Require stack:
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs:3:17)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js'
  ]
}

重现步骤:

  1. $ npm install --global fastify-cli (成功)
  2. < code>$ fastifygenerate myproject (也会产生上述错误)
  3. $ fastify (也会产生上述错误)

这可能与 fastify 没有太大关系。在我看来,全局包由于某种原因没有找到 Node,但我可能是错的。

  • 我正在使用 zshell
  • 我已经安装了 xcode
  • 我已经升级了我正在使用的节点版本
  • 我可以直接从应用程序目录启动 fastify 应用程序/不使用生成器

有什么想法吗?

I'm setting up a new mac dev machine, and have gotten node, npm, and nvm installed. All seems fine within a single project directory. However, when trying to install and use fastify-cli, I'm receiving an error:

internal/modules/cjs/loader.js:892
  throw err;
  ^

Error: Cannot find module 'node:process'
Require stack:
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs:3:17)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js'
  ]
}

Steps to reproduce:

  1. $ npm install --global fastify-cli (succeeds)
  2. $ fastify generate myproject (also produces above error)
  3. $ fastify (also produces above error)

This likely doesn't have much to do with fastify. It seems to me that the global package is not finding Node for some reason, but I may be wrong.

  • I'm using zshell
  • I've got xcode installed
  • I've upgraded the version of node i'm using
  • I'm able to start a fastify app from the app directory directly/without using the generator

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女的英雄梦 2025-01-18 10:02:15

我按照GitHub问题回复中的答案修复了错误

Node.js 14.16.0 不支持节点内部语法(例如:node:

CLI 需要节点版本 >= 14.18

步骤:

  1. 使用 nvm 将节点升级到 14.18.0(14.x 中的最后一个 lts) )。
  2. 设置默认版本14.18.0或以上。

I fixed the error following the answer in this GitHub issue reply

node internal syntax (e.g.: node:<core_module_name>) is not supported by Node.js 14.16.0

The CLI needs node version >= 14.18

Steps:

  1. Upgrade node using nvm to 14.18.0 (the last lts in 14.x).
  2. Set default version 14.18.0 or above.
剑心龙吟 2025-01-18 10:02:15

我通过将当前用户切换为root用户解决了这个问题。

如果您使用的是 Mac,请尝试切换到 root 用户帐户并再次执行相同的操作。

我在系统偏好设置下将以前的帐户指定为“管理员”,但这并不能解决问题。当我切换到我的主帐户后,问题就完美解决了。

希望这能有所帮助!

I solved it by switching the current user to a root user.

If you are using a Mac, try to switch to a root user account and do the same thing again.

I assigned my previous account as 'administrator' under system preferences, but this won't solve the issue. The problem was perfectly solved when I switched to my primary account.

Hope this could help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文