环境
- 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可能不支持。