1

尝试将 npm link 用于几个本地项目时,我遇到了问题。

假设我有两个项目,A 和 B,B 依赖于 A。另一个项目 C 也需要 A 和 B。但现在我只想专注于 A 和 B!

我从命令行执行的步骤:

  • cd进入项目A目录
  • npm install
  • 构建项目,将构建的内容输出到
    包含项目 package.json 的 dist 子文件夹(在构建
    时复制到 dist)
  • cd 到 dist 文件夹,然后run npm链接

此时,我可以在我机器上的全局 node_modules 文件夹中看到项目 A 的全局链接包。

下一个...

  • cd进入项目B目录
  • npm link projectA现在可以在我的项目 node_modules 文件夹中看到它作为符号链接文件夹列出。
  • npm 安装
  • 构建项目(也输出到带有 package.json 副本的 dist 文件夹)
  • cd 进入 dist 目录
  • 运行npm link- 错误!

因此,在尝试为项目 BI 的构建目录添加新 npm 链接的最后一步中,会出现错误:

npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "link"
npm ERR! node v6.9.2
npm ERR! npm  v3.10.9
npm ERR! code E404

npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/package-a
npm ERR! 404
npm ERR! 404  'package-a' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'package-b'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! Please include the following file with any support request:

所以我可以在这里看到 npm 正在尝试从 npm 注册表中查找包。

这是否意味着 npm 在尝试从注册表安装之前不会检查链接的包?

此外,当我npm link从项目的 dist 目录中运行命令时,它会根据在构建时复制到 dist 文件夹的 package.json 关闭并安装依赖项。有没有办法防止这种情况发生?

我确实尝试过使用 yarn 及其链接命令,运行与上述相同的步骤,但在上面详述的同一步骤中遇到完全相同的问题\相同的错误。

这可能是我的用户错误!?

4

0 回答 0