npm install loom-truffle-provider 报错

环境

  • win10
  • node v16.13.2

问题

学习CryptoZombies的教程,于是使用npm安装truffle: npm i truffle -g,结果装了老半天报错了:

...
600 verbose stack Error: The git reference could not be found
600 verbose stack     at makeError (C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\git\lib\make-error.js:26:13)
600 verbose stack     at C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\git\lib\spawn.js:37:26
600 verbose stack     at processTicksAndRejections (node:internal/process/task_queues:96:5)
600 verbose stack     at async Object.withTempDir (C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\fs\lib\with-temp-dir.js:23:14)
600 verbose stack     at async Arborist.[nodeFromEdge] (C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1101:19)
600 verbose stack     at async Arborist.[buildDepStep] (C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:970:11)
600 verbose stack     at async Arborist.buildIdealTree (C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
600 verbose stack     at async Promise.all (index 1)
600 verbose stack     at async Arborist.reify (C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:153:5)
600 verbose stack     at async Install.exec (C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\lib\commands\install.js:159:5)
601 verbose cwd C:\Users\fygame\AppData\Local\npm-cache\_cacache\tmp\git-cloneKsTTeb
602 verbose Windows_NT 10.0.19041
603 verbose node v16.13.2
604 verbose npm  v8.6.0
605 error code 1
606 error The git reference could not be found
607 error command git --no-replace-objects checkout 4.0
608 error error: pathspec '4.0' did not match any file(s) known to git
609 verbose exit 1
610 timing npm Completed in 9389ms
611 verbose unfinished npm timer reify 1653969341713
612 verbose unfinished npm timer reify:loadTrees 1653969341729
613 verbose code 1
614 error A complete log of this run can be found in:
614 error     C:\Users\fygame\AppData\Local\npm-cache\_logs\2022-05-31T03_55_41_489Z-debug-0.log

关键的错误信息是

608 error error: pathspec '4.0' did not match any file(s) known to git

联系上下文,大概是依赖包中有个gulp@4.0,然而这个版本已经被官方从git上移除了。
stackoverflow上有个一样的问题:https://stackoverflow.com/questions/70563516/npm-install-giving-error-pathspec-4-0-did-not-match-any-files-known-to-git
其中有个回答,提到用node11就好了。那咱就试试。我想只在安装truffle时使用node11,平时还是使用node16,于是引入下一个问题,如果管理多个版本的nodejs?

使用nvs管理不同版本NodeJs

很简单,npm的github上明明白白告诉你了~

  • nvm
  • nvs
  • nave
  • n
  • volta
  • nodenv
  • asdf-nodejs
  • nvm-windows
  • fnm
    nvm我之前用过,不过它没有官方的windows安装包,要通过脚本安装,略麻烦。有第三方维护的nvm-windows,不过我试了一下,安装node11.15.0时报错了,原因是它在下载npm失败了。mmm...那换一个吧,看看这个nvs,官方介绍说是受nvm启发,而且是跨平台的,感觉就比nvm高级,也有官方的windows安装包。安装后,输入命令nvs就可以选择要安装的nodejs版本,比nvm方便多啦~

说明:nvs不能改变安装目录,会安装到%LOCALAPPDATA%/nvs

C:\Users\fygame>nvs
Downloading [###########################################################################################] 100%
Extracting  [###########################################################################################] 100%
PATH += %LOCALAPPDATA%\nvs\node\11.15.0\x64

查看node版本

C:\Users\fygame>node -v
v11.15.0

查看已经安装的node

C:\Users\fygame>nvs list
 >node/11.15.0/x64

查看某个版本node的安装目录

C:\Users\fygame>nvs which 11.15.0
C:\Users\fygame\AppData\Local\nvs\node\11.15.0\x64\node.exe

呜呜,安装到C盘了,我C盘空间不大够,那把npm全局模块目录改到E盘吧:)

C:\Users\fygame>npm config set prefix E:\npm\prefix

C:\Users\fygame>npm config get prefix
E:\npm\prefix

安装下truffle试试

C:\Users\fygame>npm i truffle -g
npm WARN deprecated uuid@2.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated mkdirp-promise@5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
...
> truffle@5.5.16 postinstall E:\npm\prefix\node_modules\truffle
> node ./scripts/postinstall.js

Error: Error while attempting to download and cache solc 0.5.16: Command failed: node ./build/cli.bundled.js obtain --solc=0.5.16
    at postinstallObtain (E:\npm\prefix\node_modules\truffle\scripts\postinstall.js:13:11)
    at Object.<anonymous> (E:\npm\prefix\node_modules\truffle\scripts\postinstall.js:20:3)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
    at internal/main/run_main_module.js:21:11
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @zondax/filecoin-signing-tools@github:trufflesuite/filecoin-signing-tools-js (node_modules\truffle\node_modules\@trufflesuite\filecoin.js\node_modules\@zondax\filecoin-signing-tools):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: Error while executing:
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: undefined ls-remote -h -t ssh://git@github.com/trufflesuite/filecoin-signing-tools-js.git
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY:
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY:
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: spawn git ENOENT
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\truffle\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN ajv-formats@2.1.1 requires a peer of ajv@^8.0.0 but none is installed. You must install peer dependencies yourself.

+ truffle@5.5.16
added 1141 packages from 768 contributors in 930.877s

前面那个报错没了,但是这个新的报错(看起来似乎是执行一段安装后的脚本报错了)似乎也不影响truffle的使用。
使用下truffle看看

G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle>truffle
'truffle' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle>npx truffle
(node:6492) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added. Use emitter.setMaxListeners() to increase limit
Error: Error while attempting to download and cache solc 0.5.16: Command failed: node ./build/cli.bundled.js obtain --solc=0.5.16
    at postinstallObtain (C:\Users\admin\AppData\Roaming\npm-cache\_npx\8332\node_modules\truffle\scripts\postinstall.js:13:11)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm-cache\_npx\8332\node_modules\truffle\scripts\postinstall.js:20:3)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
    at internal/main/run_main_module.js:21:11
Error: Node version not supported. You are currently using version 11.15.0 of Node. Truffle requires Node v12.0.0 or higher.

这...truffle需要node 12.0.0以上... 看来stackoverflow也不一定靠谱。那就装个node v12.22.12吧~安装过程和上面一样。
把node12设为默认

G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle>nvs link 12.22.12
%LOCALAPPDATA%\nvs\default -> %LOCALAPPDATA%\nvs\node\12.22.12\x64

重新安装truffle,这次上面那两个报错都没有了!

G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle>npm i truffle -S
npm WARN deprecated uuid@2.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated mkdirp-promise@5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated cids@0.7.5: This module has been superseded by the multiformats module
npm WARN deprecated multicodec@0.5.7: This module has been superseded by the multiformats module
npm WARN deprecated multicodec@1.0.4: This module has been superseded by the multiformats module
npm WARN deprecated multibase@0.6.1: This module has been superseded by the multiformats module
npm WARN deprecated multibase@0.7.0: This module has been superseded by the multiformats module
npm WARN deprecated uuid@3.2.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated node-pre-gyp@0.11.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm WARN deprecated cids@1.1.9: This module has been superseded by the multiformats module
npm WARN deprecated multibase@3.1.2: This module has been superseded by the multiformats module
npm WARN deprecated multibase@4.0.6: This module has been superseded by the multiformats module
npm WARN deprecated multicodec@3.2.1: This module has been superseded by the multiformats module
npm WARN deprecated ipld-dag-pb@0.20.0: This module has been superseded by @ipld/dag-pb and multiformats
npm WARN deprecated ipld-dag-cbor@0.17.1: This module has been superseded by @ipld/dag-cbor and multiformats
npm WARN deprecated multicodec@2.1.3: This module has been superseded by the multiformats module
npm WARN deprecated ipld-raw@6.0.0: This module has been superseded by the multiformats module
npm WARN deprecated @nodefactory/filsnap-adapter@0.2.2: Package is deprecated in favour of @chainsafe/filsnap-adapter

> @trufflesuite/bigint-buffer@1.1.9 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\ganache\node_modules\@trufflesuite\bigint-buffer
> node-gyp-build || echo "Couldn't build bindings. Non-native version used."


> bufferutil@4.0.5 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\ganache\node_modules\bufferutil
> node-gyp-build


> keccak@3.0.1 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\ganache\node_modules\keccak
> node-gyp-build || exit 0


> leveldown@6.1.0 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\ganache\node_modules\leveldown
> node-gyp-build


> secp256k1@4.0.2 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\ganache\node_modules\secp256k1
> node-gyp-build || exit 0


> utf-8-validate@5.0.7 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\ganache\node_modules\utf-8-validate
> node-gyp-build


> iso-constants@0.1.2 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\iso-constants
> node build.js > index.browser.js


> bufferutil@4.0.6 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\bufferutil
> node-gyp-build


> secp256k1@4.0.3 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\secp256k1
> node-gyp-build || exit 0


> ursa-optional@0.10.2 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\ursa-optional
> node rebuild.js

ursaNative bindings compilation fail. This is not an issue. Modules that depend on it will use fallbacks.

> utf-8-validate@5.0.9 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\utf-8-validate
> node-gyp-build


> keccak@3.0.2 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\keccak
> node-gyp-build || exit 0


> leveldown@5.6.0 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\leveldown
> node-gyp-build


> sqlite3@4.2.0 install G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
[sqlite3] Success: "G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\sqlite3\lib\binding\node-v72-win32-x64\node_sqlite3.node" is installed via remote

> @apollo/protobufjs@1.2.2 postinstall G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\@apollo\protobufjs
> node scripts/postinstall


> protobufjs@6.11.3 postinstall G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\protobufjs
> node scripts/postinstall


> es5-ext@0.10.61 postinstall G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\es5-ext
>  node -e "try{require('./_postinstall')}catch(e){}" || exit 0


> web3-shh@1.5.3 postinstall G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\web3-shh
> echo "WARNING: the web3-shh api will be deprecated in the next version"

"WARNING: the web3-shh api will be deprecated in the next version"

> web3-bzz@1.5.3 postinstall G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\web3-bzz
> echo "WARNING: the web3-bzz api will be deprecated in the next version"

"WARNING: the web3-bzz api will be deprecated in the next version"

> web3@1.5.3 postinstall G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\web3
> echo "WARNING: the web3-shh and web3-bzz api will be deprecated in the next version"

"WARNING: the web3-shh and web3-bzz api will be deprecated in the next version"

> truffle@5.5.16 postinstall G:\tgit\eth\cryptozombiestrial\oracle\EthPriceOracle\node_modules\truffle
> node ./scripts/postinstall.js

- Fetching solc version list from solc-bin. Attempt #1
- Fetching solc version list from solc-bin. Attempt #1
- Fetching solc version list from solc-bin. Attempt #1
- Downloading compiler. Attempt #1.
- Fetching solc version list from solc-bin. Attempt #1
- Downloading compiler. Attempt #1.
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN notsup Unsupported engine for peer-id@0.14.8: wanted: {"node":">=14.0.0"} (current: {"node":"12.22.12","npm":"6.14.16"})
npm WARN notsup Not compatible with your version of node/npm: peer-id@0.14.8
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @zondax/filecoin-signing-tools@github:trufflesuite/filecoin-signing-tools-js (node_modules\@trufflesuite\filecoin.js\node_modules\@zondax\filecoin-signing-tools):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Error while executing:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: D:\Program Files\Git\cmd\git.EXE ls-remote -h -t ssh://git@github.com/trufflesuite/filecoin-signing-tools-js.git
npm WARN optional SKIPPING OPTIONAL DEPENDENCY:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: ssh: connect to host github.com port 22: Connection refused
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fatal: Could not read from remote repository.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Please make sure you have the correct access rights
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: and the repository exists.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: exited with error code: 128
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN ajv-formats@2.1.1 requires a peer of ajv@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN EthPriceOracle@1.0.0 No description
npm WARN EthPriceOracle@1.0.0 No repository field.

+ truffle@5.5.16
added 1141 packages from 768 contributors and audited 1144 packages in 242.581s

100 packages are looking for funding
  run `npm fund` for details

found 16 vulnerabilities (6 low, 4 moderate, 6 high)
  run `npm audit fix` to fix them, or `npm audit` for details

结论

安装truffle,需要node v12.0.0以上(我用的v12.22.12),node v16.13.2可能不支持。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,265评论 6 490
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,078评论 2 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,852评论 0 347
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,408评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,445评论 5 384
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,772评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,921评论 3 406
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,688评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,130评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,467评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,617评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,276评论 4 329
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,882评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,740评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,967评论 1 265
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,315评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,486评论 2 348

推荐阅读更多精彩内容