错误!代码 EJSONPARSE npm install with husky 和 lint-staged
npm ERR! code EJSONPARSE npm install with husky and lint-staged
我的 package.json 可以在没有 husky 和 lint-staged 的情况下工作,但不能跟他们。
它在说:
npm ERR! code EJSONPARSE
npm ERR! file C:\Proyectos\my-app\package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token in JSON at position 1254 while parsing near '...
npm ERR! JSON.parse "lint-staged": {
npm ERR! JSON.parse "*.{...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
我在package.json中添加的是...
"husky": {
"hooks": {
"pre-commit": "npm run test && prettier --write",
"pre-push": "npm run test && prettier --write"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"prettier --write",
"git add"
]
}
有些用户要求我上传整个package.json,所以这是代码...
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.19.3",
"@types/react": "^16.9.55",
"@types/react-dom": "^16.9.9",
"@types/styled-components": "^5.1.4",
"lint-staged": "^10.5.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"typescript": "^4.0.5",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"prettier": "2.1.2",
"styled-components": "^5.2.1"
},
"husky": {
"hooks": {
"pre-commit": "npm run test && prettier --write",
"pre-push": "npm run test && prettier --write"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"prettier --write",
"git add"
]
}
}
现在试试这个,
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.19.3",
"@types/react": "^16.9.55",
"@types/react-dom": "^16.9.9",
"@types/styled-components": "^5.1.4",
"lint-staged": "^10.5.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"typescript": "^4.0.5",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"prettier": "2.1.2",
"styled-components": "^5.2.1"
},
"husky": {
"hooks": {
"pre-commit": "npm run test && prettier --write",
"pre-push": "npm run test && prettier --write"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"prettier --write",
"git add"
]
}
}
验证 package.json
检查 package.json
文件。它可能包含我们必须删除的额外逗号 (,) 或双引号 ("")。
这对我有用。
我的 package.json 可以在没有 husky 和 lint-staged 的情况下工作,但不能跟他们。 它在说:
npm ERR! code EJSONPARSE
npm ERR! file C:\Proyectos\my-app\package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token in JSON at position 1254 while parsing near '...
npm ERR! JSON.parse "lint-staged": {
npm ERR! JSON.parse "*.{...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
我在package.json中添加的是...
"husky": { "hooks": { "pre-commit": "npm run test && prettier --write", "pre-push": "npm run test && prettier --write" } }, "lint-staged": { "*.{ts,tsx}": [ "prettier --write", "git add" ] }
有些用户要求我上传整个package.json,所以这是代码...
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.19.3",
"@types/react": "^16.9.55",
"@types/react-dom": "^16.9.9",
"@types/styled-components": "^5.1.4",
"lint-staged": "^10.5.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"typescript": "^4.0.5",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"prettier": "2.1.2",
"styled-components": "^5.2.1"
},
"husky": {
"hooks": {
"pre-commit": "npm run test && prettier --write",
"pre-push": "npm run test && prettier --write"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"prettier --write",
"git add"
]
}
}
现在试试这个,
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.19.3",
"@types/react": "^16.9.55",
"@types/react-dom": "^16.9.9",
"@types/styled-components": "^5.1.4",
"lint-staged": "^10.5.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"typescript": "^4.0.5",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"prettier": "2.1.2",
"styled-components": "^5.2.1"
},
"husky": {
"hooks": {
"pre-commit": "npm run test && prettier --write",
"pre-push": "npm run test && prettier --write"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"prettier --write",
"git add"
]
}
}
package.json
检查 package.json
文件。它可能包含我们必须删除的额外逗号 (,) 或双引号 ("")。
这对我有用。