You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Create React App构建时能否禁用ESLint?Heroku部署问题求解

Solutions to Skip ESLint or Disable Prettier Plugin in Heroku Build for CRA

Got it, let's fix this without enabling NPM_CONFIG_PRODUCTION=false or hiding your ESLint config. Here are a few practical approaches:

1. Disable ESLint Entirely During Production Build

Create React App lets you skip ESLint checks in the build process using an environment variable. Just update your package.json scripts to include this variable when running build:

{
  "scripts": {
    "start": "react-scripts start",
    "build": "DISABLE_ESLINT_PLUGIN=true react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }
}

This tells CRA to skip all ESLint validation during the build step. Your local development workflow won't be affected—ESLint will still run normally when you use start or test, or if you run it manually.

2. Conditionally Load Prettier Plugin Only in Development

If you still want ESLint to run in production but just skip the Prettier plugin, convert your .eslintrc.json to a JavaScript config file (.eslintrc.js) so you can add environment-based logic. Here's how:

  1. Rename .eslintrc.json to .eslintrc.js
  2. Update the file to conditionally include the Prettier plugin only when NODE_ENV is development:
module.exports = {
  extends: ["react-app"],
  ...(process.env.NODE_ENV === "development" ? {
    plugins: ["prettier"],
    rules: {
      "prettier/prettier": "error"
    }
  } : {})
};

Now, when Heroku runs the build (with NODE_ENV=production), ESLint won't attempt to load the eslint-plugin-prettier module, so no missing module error. You'll still get Prettier's linting benefits locally during development.

3. (Optional) Move ESLint Prettier Plugin to Dependencies

While this isn't ideal for strict dev dependency practices, you could move eslint-plugin-prettier to dependencies instead of devDependencies in your package.json. Heroku will install production dependencies by default, so the plugin will be available during build:

npm uninstall eslint-plugin-prettier --save-dev
npm install eslint-plugin-prettier --save

This works, but it adds a dev-only tool to your production dependency tree, which most developers prefer to avoid. Use this only if the first two options don't fit your workflow.


内容的提问来源于stack exchange,提问作者Derek

火山引擎 最新活动