Heroku 无法加载要扩展的配置 "google"。引用自:/app/.eslintrc.json

Heroku failed to load config "google" to extend from. Referenced from: /app/.eslintrc.json

在本地,我的项目运行没有错误,但是在Heroku上部署项目后,出现了以下错误:

同样,本地一切正常。这里是 eslintrc.json:

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": ["eslint:recommended", "google"],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": ["react", "@typescript-eslint"],
  "rules": {
    "camelcase": "off",
    "object-curly-spacing": "off",
    "linebreak-style": 0,
    "isolatedModules": 0,
    "indent": "off",
    "require-jsdoc": "off",
    "max-len": "off",
    "no-unused-vars": "off",
    "no-invalid-this": "warn",
    "operator-linebreak": "off"
  },
  "globals": {
    "google": "readonly",
    "process": "readonly",
    "arrow-parens": "off"
  }
}

您通常在生产环境中不需要 ESlint。在开发模式下使用 linter 验证代码是一种很好的做法。关于生产,在几乎所有情况下,禁用它都是有意义的。

这就是为什么即使是 ESlint 的官方文档也建议使用 --dev 标志安装它 (https://eslint.org/docs/user-guide/getting-started):

yarn add eslint --dev

在这种情况下,ESlint 将添加到您的 package.json"devDependencies"

现在,让我们回到错误。我想,您通过以下方式部署您的应用程序:

yarn install --production
yarn build

(或npm类比这些命令)

它是 运行 在主机上还是在 docker 容器中并不重要。重点是在运行ning这些命令之前,需要设置环境变量DISABLE_ESLINT_PLUGINtrue.

尝试

export DISABLE_ESLINT_PLUGIN=true
yarn install --production
yarn build

如果您直接在主机上部署应用程序。

或者这样做:

ENV DISABLE_ESLINT_PLUGIN true
RUN ["yarn", "install", "--production"]
RUN ["yarn", "build"]

如果您的应用已 docker 化。