简体   繁体   中英

Javascript Eslint Error: Cannot find module 'optionator'

We've got some error and we try to install optionator but nothing happened. We're using Linux

We're trying to npm i from package.json which include this dependencies

"optionalDependencies": { 
  "eslint-config-<name>": "github:<username>/<repo>" 
} 

then we tried to run npm i optionator but still get the same error


    Error: Cannot find module 'optionator'
    Require stack:
    - /usr/share/nodejs/eslint/lib/options.js
    - /usr/share/nodejs/eslint/lib/cli.js
    - /usr/share/nodejs/eslint/bin/eslint.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
    at Function.Module._load (internal/modules/cjs/loader.js:730:27)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/usr/share/nodejs/eslint/lib/options.js:12:20)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/usr/share/nodejs/eslint/lib/options.js',
    '/usr/share/nodejs/eslint/lib/cli.js',
    '/usr/share/nodejs/eslint/bin/eslint.js'

Anyone who experienced this, please help us. Thanks

So if you have not done an npm init then that is the issue. npm init initializes the project and will add the node_modules folder to the working directory, this will set it up as a node project. Then to install a dependency just run a npm install <dependency> although I do recommend doing a --save afterwards as well as it just ensures that the package is put in your current directory

$ npm init
$ npm install optionator --save

npm-init | npm Docs

Need to give full access to package-lock.json

Nothing worked until when I initialized the project in a new directory and reinstalled all the dependent modules afresh.

If you are using linux do this

sudo eslint init

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM