【问题标题】:npm ERR! code EJSONPARSE npm install with husky and lint-stagednpm 错误!使用 husky 和 ​​lint-staged 编码 EJSONPARSE npm install
【发布时间】:2021-03-02 17:49:52
【问题描述】:

我的 package.json 可以在没有 huskylint-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 中添加的是...

“哈士奇”:{ “钩子”:{ "pre-commit": "npm run test && prettier --write", "pre-push": "npm run test && prettier --write" } }, “lint-staged”:{​​​​​​​​ “*.{​​​​​​​​​ts,tsx}​​​​​​​​”:[ “更漂亮——写”, “混帐添加” ] }​​​​​​​​​

有些用户要求我上传整个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"
    ]
  }
}

【问题讨论】:

    标签: node.js package.json prettier husky lint-staged


    【解决方案1】:

    现在试试这个,

    {
        "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的工作副本
    • 是的,但没有,我有新错误npm ERR! code ELIFECYCLE
    【解决方案2】:

    使用https://jsonlint.com/ 验证package.json

    检查package.json 文件。它可能包含我们必须删除的额外逗号 (,) 或双引号 ("")。

    这对我有用。

    【讨论】:

      猜你喜欢
      • 2020-01-19
      • 2020-08-18
      • 2019-01-15
      • 2022-08-21
      • 2020-11-08
      • 2018-02-26
      • 1970-01-01
      • 2020-07-16
      相关资源
      最近更新 更多