Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module is extraneous npm

I've checked that the connect-privkey-to-provider module is in the dependencies. However, it keeps saying Module 'connect-privkey-to-provider' is extraneous npm and cannot find module 'connect-privkey-to-provider'.

What's wrong with my code?

PS C:\Users\1Sun\addition-game-starter> truffle deploy --network klaytn Error: Cannot find module 'connect-privkey-to-provider' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) at Function.Module._load (internal/modules/cjs/loader.js:508:25) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at Object. (C:\Users\1Sun\addition-game-starter\truffle.js:2:29) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at Function.Config.load (C:\Users\1Sun\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-config\index.js:254:1) at Function.Config.detect (C:\Users\1Sun\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-config\index.js:243:1) at Object.run (C:\Users\1Sun\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-core\lib\commands\migrate.js:35:1) at Command.run (C:\Users\1Sun\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-core\lib\command.js:101:1) at Object. (C:\Users\1Sun\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-core\cli.js:22:1) at webpack_require (C:\Users\1Sun\AppData\Roaming\npm\node_modules\truffle\build\webpack:\webpack\bootstrap 0791995565e53f633c90:19:1) at C:\Users\1Sun\AppData\Roaming\npm\node_modules\truffle\build\webpack:\webpack\bootstrap 0791995565e53f633c90:65:1 at Object. (C:\Users\1Sun\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:71:10) at 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,
        }
    }
}

Error

enter image description here

enter image description here

like image 538
1Sun Avatar asked May 20 '19 13:05

1Sun


People also ask

What does extraneous mean in npm?

extraneous means a package is installed but is not listed in your project's package. json . Since you're listing packages that have been installed globally, it's going to give you a lot of extraneous errors that can be simply ignored because most things installed globally will not be in your project's package.

How do you fix npm err extraneous?

To resolve extraneous errors in the npm list output, you need to add the packages in your package. json file. Once the upgrade is done, run the npm list command again to see if the extraneous error is still there. Then run the npm install command to install the dependencies again.

How do I get rid of extraneous?

Click the extra blank page to select it and hit the DELETE button on your keyboard to remove it. You can also remove this extra blank page by simply pressing the BACKSPACE key.

How do I remove unused npm packages?

You can use npm-prune to remove extraneous packages. Extraneous packages are packages that are not listed on the parent package's dependencies list. If the --production flag is specified or the NODE_ENV environment variable is set to production, this command will remove the packages specified in your devDependencies.


2 Answers

Your code works fine in my environment. Try to do these:

  • Remove node_modules
  • Remove package-lock.json
  • Update truffle package npm update -g truffle
  • Reinstall, using command npm i

After that just change solidity version in contracts folder

pragma solidity ^0.5.0;
like image 71
Yegor Zaremba Avatar answered Oct 19 '22 07:10

Yegor Zaremba


In my case for changing some dependencies, I was deleting node_modules, but I had to erase package-lock.json too.

I closed all windows, deleted node_modules folder and package-lock.json and reinstalled it all again with npm install.

like image 2
nativelectronic Avatar answered Oct 19 '22 07:10

nativelectronic