配置webpack打包报错:
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.- configuration.devtool should match pattern "^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map$". BREAKING CHANGE since webpack 5: The devtool option is more strict. Please strictly follow the order of the keywords in the pattern百度说是版本不兼容问题,就是假设你webpack版本是5,但是用到的插件版本还是4,不兼容webpack5。
所以此时你可以选择降级webpack,
npm install webpack@4.41.5
之后又报错:
TypeError: Cannot read properties of undefined (reading ‘tap’)
还是百度的答案:将webpack降级后,html-webpack-plugin需要和webpack保持同一个版本,这里我执行了:npm install html-webpack-plugin@4.41.5会报错,去了npm官网,只需要@4就行了
npm i --save-dev html-webpack-plugin@4
最后解决了问题。
博客讲述了在配置Webpack打包时遇到的错误,包括`Invalid configuration object`和`TypeError: Cannot read properties of undefined (reading 'tap')`。作者通过百度搜索找到了问题原因,即Webpack版本与某些插件版本不兼容。解决方案是降级Webpack到4.41.5版本,并确保html-webpack-plugin与Webpack版本一致。执行相关npm安装命令后,问题最终得到解决。
369





