Install eslint with npm:
npm install -g eslint
This is contents of my package.json:
$ cat package.json
"extends":"eslint:recommended"
Initiate my eslint:
$ eslint --init
? How would you like to configure ESLint? Use a popular style guide
? Which style guide do you want to follow? Standard
? What format do you want your config file to be in? JSON
Checking peerDependencies of eslint-config-standard@latest
Installing eslint-config-standard@latest, eslint-plugin-import@>=2.8.0, eslint-plugin-node@>=5.2.1, eslint-plugin-promise@>=3.6.0, eslint-plugin-standard@>=3.0.1
npm ERR! file /home/debian9/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token : in JSON at position 9 while parsing near '"extends":"eslint:recommended...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/debian9/.npm/_logs/2018-05-18T02_27_01_552Z-debug.log
Successfully created .eslintrc.json file in /home/debian9
Check a test.js file with eslint:
$ eslint /tmp/test.js
Unexpected token : in JSON at position 9
SyntaxError: Unexpected token : in JSON at position 9
at JSON.parse (<anonymous>)
at new IgnoredPaths (/home/debian9/.nvm/versions/node/v9.8.0/lib/node_modules/eslint/lib/ignored-paths.js:176:55)
at lodash.memoize.optionsObj (/home/debian9/.nvm/versions/node/v9.8.0/lib/node_modules/eslint/lib/util/glob-util.js:115:13)
at memoized (/home/debian9/.nvm/versions/node/v9.8.0/lib/node_modules/eslint/node_modules/lodash/lodash.js:10551:27)
at globPatterns.forEach.pattern (/home/debian9/.nvm/versions/node/v9.8.0/lib/node_modules/eslint/lib/util/glob-util.js:162:34)
at Array.forEach (<anonymous>)
at Object.listFilesToProcess (/home/debian9/.nvm/versions/node/v9.8.0/lib/node_modules/eslint/lib/util/glob-util.js:158:18)
at CLIEngine.executeOnFiles (/home/debian9/.nvm/versions/node/v9.8.0/lib/node_modules/eslint/lib/cli-engine.js:518:35)
at Object.execute (/home/debian9/.nvm/versions/node/v9.8.0/lib/node_modules/eslint/lib/cli.js:189:111)
at Object.<anonymous> (/home/debian9/.nvm/versions/node/v9.8.0/lib/node_modules/eslint/bin/eslint.js:74:28)
How can I fix my eslint configuration?
The error is pretty clear:
npm ERR! file /home/debian9/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
package.json must contain a valid JSON.
So run: npm init to generate a valid one and then add your eslintConfig to it
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"eslintConfig": {
"extends": "eslint:recommended"
}
}
All your eslint configuration, must be inside eslintConfig property on your package.json. You can read the documentation in here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With