5

I have an app initiated using Create React App, so npm run build runs react-scripts build. I recently installed prettier and so added a .eslintrc.json file to the project root to load the prettier plugin. npm run build works as expected locally, but, when deploying the app to Heroku, npm run build tries to run ESLint and fails because the plugins are devDependencies rather than dependencies.

Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier'

From prior wrangling with a similar issue, I know that I can set NPM_CONFIG_PRODUCTION=false in Heroku so that it will install devDependencies, which actually does resolve the deployment issue. Nevertheless, I'm curious to learn if there's another solution that doesn't require setting NPM_CONFIG_PRODUCTION=false.

Is it possible to prevent npm run build in this scenario from running ESLint altogether or to prevent it from trying to access the plugins specified in .eslintrc.json? I acknowledge that adding .eslintrc.json to .gitignore is one solution, but I want the ESLint configuration in my repo.

Derek
  • 827
  • 11
  • 23
  • 1
    Did you solve this issue? Could you please help? I have the same :-( – Oleksii Sytar Feb 14 '22 at 16:30
  • @OleksiiSytar looking back on my commit history for the project I was working on when I ran into this, I don't think I did solve it. I just had to keep `NPM_CONFIG_PRODUCTION=false` in my Heroku config :( – Derek Feb 14 '22 at 23:57

2 Answers2

0

you can run "npm run eject" to generate webpack configuration files, and then modify "webpack.config.js",delete the eslint configuration

0

Have you tried running this:

"build": "DISABLE_ESLINT_PLUGIN=true react-scripts build",

This will disable the eslint during the build phase.

medev21
  • 2,469
  • 8
  • 31
  • 43