运行npm install
后,我注意到有时会package-lock.json
更改。
本节:
"dependencies": {
"websocket": {
"version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"from": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"requires": {
"debug": "^2.2.0",
"nan": "^2.3.3",
"typedarray-to-buffer": "^3.1.2",
"yaeti": "^0.0.6"
}
}
}
}
对此的更改:
"dependencies": {
"websocket": {
"version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"from": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"requires": {
"debug": "^2.2.0",
"nan": "^2.3.3"
}
}
}
}
当发生这种情况时,我收到运行时错误:
module.js:538
throw err;
^
Error: Cannot find module 'typedarray-to-buffer'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\...\node_modules\web3-providers-ws\node_modules\websocket\lib\W3CWebSocket.js:18:16)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
经过一些调试后,我的代码中的require("web3")
会出现此错误。
以下是我的package.json
文件中的相关部分:
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.0.0",
"bignumber.js": "^7.0.0",
"decimal.js": "^10.0.0",
"web3": "1.0.0-beta.34",
"ethereumjs-testrpc-sc": "6.1.2",
"ganache-cli": "6.1.0",
"solidity-coverage": "0.4.14",
"truffle": "4.1.3"
}
任何人都可以告诉我如何解决这个问题,以及为什么npm
不时会以不同的方式运作?
谢谢。