安装 npm 包时 /src 是啥意思?

Posted

技术标签:

【中文标题】安装 npm 包时 /src 是啥意思?【英文标题】:What the /src means when installing npm package?安装 npm 包时 /src 是什么意思? 【发布时间】:2021-12-10 13:50:36 【问题描述】:

我尝试(再次)构建一个运行良好的 React 项目,然后客户打电话给我并告诉我它已经崩溃了。

在构建(npm run build)时,我得到了这个:

Creating an optimized production build...
Failed to compile.

./src/utils/graphql.js
Cannot find module: 'graphql-tag/src'. Make sure this package is installed.

You can install this package by running: npm install graphql-tag/src.

但是,当我运行给定 npm install graphql-tag/src 的命令时,它只会让超时尝试 ssh 进入似乎是 github 存储库的内容。我只是不明白为什么它会尝试使用 SSH,因为我知道当我查看 packages.json 文件时,我只能找到一个指向该特定包的 github 存储库的 http URL。

我尝试以经典的方式安装软件包 npm install graphql-tag,它运行良好,但是当我重新启动构建时,我遇到了同样的失败。

我什至尝试使用其 github 存储库的 URL(https://github.com/apollographql/graphql-tag | 使用 google 搜索找到)直接安装该软件包,但它最终以相同的方式结束。

我还尝试删除文件夹 node_modules 并重新安装所有npm i

最后,当我使用cat /home/plagiat/.npm/_logs/2021-10-25T00_40_42_148Z-debug.log 查看日志文件时,使用建议的命令npm install graphql-tag/src 得到的结果是这样的

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install', 'graphql-tag/src' ]
2 info using npm@6.14.11
3 info using node@v12.21.0
4 verbose npm-session a25edec68e8c749c
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly pacote Retrying git command: ls-remote -h -t git://github.com/graphql-tag/src.git attempt # 2
8 silly pacote Retrying git command: ls-remote -h -t git://github.com/graphql-tag/src.git attempt # 3
9 silly pacote Retrying git command: ls-remote -h -t ssh://git@github.com/graphql-tag/src.git attempt # 2
10 silly pacote Retrying git command: ls-remote -h -t ssh://git@github.com/graphql-tag/src.git attempt # 3
11 silly fetchPackageMetaData error for github:graphql-tag/src Error while executing:
11 silly fetchPackageMetaData /usr/bin/git ls-remote -h -t ssh://git@github.com/graphql-tag/src.git
11 silly fetchPackageMetaData
11 silly fetchPackageMetaData ssh: connect to host github.com port 22: Connection timed out
11 silly fetchPackageMetaData fatal: Could not read from remote repository.
11 silly fetchPackageMetaData
11 silly fetchPackageMetaData Please make sure you have the correct access rights
11 silly fetchPackageMetaData and the repository exists.
11 silly fetchPackageMetaData
11 silly fetchPackageMetaData exited with error code: 128
12 timing stage:rollbackFailedOptional Completed in 0ms
13 timing stage:runTopLevelLifecycles Completed in 53964ms
14 verbose stack Error: exited with error code: 128
14 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/pacote/lib/util/finished.js:12:19)
14 verbose stack     at ChildProcess.emit (events.js:314:20)
14 verbose stack     at maybeClose (internal/child_process.js:1022:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
15 verbose cwd /home/plagiat/AntiPlagiat/client
16 verbose Linux 5.4.0-73-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "graphql-tag/src"
18 verbose node v12.21.0
19 verbose npm  v6.14.11
20 error Error while executing:
20 error /usr/bin/git ls-remote -h -t ssh://git@github.com/graphql-tag/src.git
20 error
20 error ssh: connect to host github.com port 22: Connection timed out
20 error fatal: Could not read from remote repository.
20 error
20 error Please make sure you have the correct access rights
20 error and the repository exists.
20 error
20 error exited with error code: 128
21 verbose exit [ 1, true ]

任何见解将不胜感激。

【问题讨论】:

您的/src/utils/graphql.js 中有什么内容?你如何导入graphql-tag 【参考方案1】:

在您的情况下,src/ folder 与 npm install 一起使用时,会触发安装其自己的 package.json 内容 (as in here)(如果存在)。

但是,如果无法访问 SSH URL,您应该switch to HTTPS。

git config --global url.https://github.com/.insteadOf git://github.com/

【讨论】:

以上是关于安装 npm 包时 /src 是啥意思?的主要内容,如果未能解决你的问题,请参考以下文章

当我尝试在 R 中安装 Mosaic 包时,这个错误是啥意思?

package.json 里的 devDependencies 是啥意思

npm 的“跳过失败的可选依赖项”是啥意思?

IDEA 导入jar包时 显示empty 是啥意思?

在 npm 包中,依赖版本的空字符串 ("") 是啥意思?

运行“npm install”时,“x 软件包正在寻找资金”是啥意思?