模块无关npm

时间:2019-05-20 13:25:33

标签: npm node-modules solidity truffle

我显然检查了依赖项中是否有connect-privkey-to-provider个模块。但是,它一直说 模块'connect-privkey-to-provider'是无关的npm  和 找不到模块'connect-privkey-to-provider'

我的代码怎么了?

  

PS C:\ Users \ 1Sun \ addition-game-starter>松露部署--network   克莱滕       错误:找不到模块“向提供者连接私钥”           在Function.Module._resolveFilename(内部/模块/cjs/loader.js:582:15)           在Function.Module._load(内部/模块/cjs/loader.js:508:25)           在Module.require(internal / modules / cjs / loader.js:637:17)           在要求时(内部/模块/cjs/helpers.js:22:18)           在对象。 (C:\ Users \ 1Sun \ addition-game-starter \ truffle.js:2:29)           在Module._compile(内部/模块/cjs/loader.js:701:30)           在Object.Module._extensions..js(内部/模块/cjs/loader.js:712:10)           在Module.load(internal / modules / cjs / loader.js:600:32)           在tryModuleLoad(内部/模块/cjs/loader.js:539:12)           在Function.Module._load(内部/模块/cjs/loader.js:531:3)           在Module.require(internal / modules / cjs / loader.js:637:17)           在要求时(内部/模块/cjs/helpers.js:22:18)           在Function.Config.load(C:\ Users \ 1Sun \ AppData \ Roaming \ npm \ node_modules \ truffle \ build \ webpack:\ packages \ truffle-config \ index.js:254:1)           在Function.Config.detect(C:\ Users \ 1Sun \ AppData \ Roaming \ npm \ node_modules \ truffle \ build \ webpack:\ packages \ truffle-config \ index.js:243:1)           在Object.run(C:\ Users \ 1Sun \ AppData \ Roaming \ npm \ node_modules \ truffle \ build \ webpack:\ packages \ truffle-core \ lib \ commands \ migrate.js:35:1)           在Command.run(C:\ Users \ 1Sun \ AppData \ Roaming \ npm \ node_modules \ truffle \ build \ webpack:\ packages \ truffle-core \ lib \ command.js:101:1)           在对象。 (C:\ Users \ 1Sun \ AppData \ Roaming \ npm \ node_modules \ truffle \ build \ webpack:\ packages \ truffle-core \ cli.js:22:1)           在 webpack_require 中(C:\ Users \ 1Sun \ AppData \ Roaming \ npm \ node_modules \ truffle \ build \ webpack:\ webpack \ bootstrap   0791995565e53f633c90:19:1)           在C:\ Users \ 1Sun \ AppData \ Roaming \ npm \ node_modules \ truffle \ build \ webpack:\ webpack \ bootstrap   0791995565e53f633c90:65:1           在对象。 (C:\ Users \ 1Sun \ AppData \ Roaming \ npm \ node_modules \ truffle \ build \ cli.bundled.js:71:10)           在Module._compile(internal / modules / cjs / loader.js:701:30)


package.json

{
  "name": "klay-dapp-boilerplate",
  "version": "0.0.1",
  "description": "boilerplate for klaytn-based app",
  "main": "truffle.js",
  "scripts": {
    "build": "webpack",
    "dev": "webpack-dev-server"
  },
  "dependencies": {
    "caver-js": "^0.0.2-m",
    "connect-privkey-to-provider": "^0.0.3",
    "spin.js": "^4.0.0"
  },
  "devDependencies": {
    "copy-webpack-plugin": "^4.6.0",
    "eslint": "^4.19.1",
    "webpack": "^4.7.0",
    "webpack-cli": "^3.1.1",
    "webpack-dev-server": "^3.1.4"
  },
  "eslintConfig": {
    "env": {
      "browser": true,
      "node": true
    }
  }
}

truffle.js

// truffle.js config for klaytn.
const PrivateKeyConnector = require('connect-privkey-to-provider')
const NETWORK_ID = '1001'
const GASLIMIT = '20000000'
const URL ='https://api.baobab.klaytn.net:8651'
const PRIVATE_KEY = '0x80ea7e298ba2cbf484e6c0c0703ccf2ea94be7f8a1a097fc013042b4888a2e80'

module.exports = {
    networks: {
        klaytn: {
            provider: new PrivateKeyConnector(PRIVATE_KEY, URL),
            network_id: NETWORK_ID,
            gas: GASLIMIT,
            gasPrice: null,
        }
    }
}

错误

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:1)

您的代码在我的环境中可以正常工作。尝试执行以下操作:

  • 删除node_modules
  • 删除package-lock.json
  • 更新truffle程序包npm update -g truffle
  • 使用命令npm i
  • 重新安装

之后,只需更改solidity version文件夹中的contracts

pragma solidity ^0.5.0;

答案 1 :(得分:0)

在我更改某些依赖项的情况下,我删除了 node_modules,但我也必须删除 package-lock.json。 所以我关闭所有窗口,删除 node_modules 文件夹并删除 package-lock.json,然后使用 npm install 重新安装。