create-react-app: Cannot create build: TypeError: Ajv is not a constructor

Steps To Reproduce

  1. Update to latest react-scripts (5.0.0)
  2. Do npm run build.

The current behavior

home/node/frontend/node_modules/mini-css-extract-plugin/node_modules/schema-utils/dist/validate.js:66
const ajv = new Ajv({
            ^
TypeError: Ajv is not a constructor
    at Object.<anonymous> (/home/node/frontend/node_modules/mini-css-extract-plugin/node_modules/schema-utils/dist/validate.js:66:13)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:11[55](https://firelight.smokescreen.io/v4/frontend/-/jobs/95213#L55):10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/node/frontend/node_modules/mini-css-extract-plugin/node_modules/schema-utils/dist/index.js:6:5)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 20
  • Comments: 15

Most upvoted comments

I got this fixed after uninstalling npm-force-resolutions and removing all preinstall related to that. And then

  • rm -rf node_modules
  • rm package-lock.json
  • npm install

Same issue here. Sometimes it works and sometimes it doesn’t.

Also happens on npm run start for me

This is very painful, every time you add a new dependency you have to rm -rf node_modules and install it again.

Any updates on this are very much appreciated 🙏