简体   繁体   English

TypeError:当我运行 npm 运行构建时,Ajv 不是构造函数

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

I'm stumbling on an error every time I run npm run build每次运行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谢谢

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.我发现如果我删除 node_modules 和 package-lock.json 然后运行npm installnpm run build ,就可以解决它。 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.将 mini-css-extract-plugin 降级到 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.我从 2.5.3 开始测试了每个版本,这是没有出现此错误的最新版本。

It would be nice to know why this works, but it does.很高兴知道为什么会这样,但确实如此。

Solution was to migrate from npm to yarn as following: stackoverflow.com/a/71481424/6027872解决方案是从 npm 迁移到纱线如下: stackoverflow.com/a/71481424/6027872

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM