TypeError: Ajv is not a constructor when I run npm run build

Viewed 2386

I'm stumbling on an error every time I run npm run build

error:

/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/ts34mpr/website/client/node_modules/mini-css-extract-plugin/node_modules/schema-utils/dist/validate.js:66:13)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153: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/ts34mpr/website/client/node_modules/mini-css-extract-plugin/node_modules/schema-utils/dist/index.js:6:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

please does anyone knows the solution or can help please! Thank you

3 Answers

Same problem for me. I find if I delete node_modules and package-lock.json and then run npm install and npm run build, that solves it. Not a great answer. I'd like to know the real solution.

I have a more permanent answer than my previous one. Downgrade mini-css-extract-plugin to 2.4.7. For example:

"mini-css-extract-plugin": "2.4.7",

I tested each version from 2.5.3 down and this is most recent version where this error does not occur.

It would be nice to know why this works, but it does.

Related