next项目打包构建报错
报错如下:
npm WARN deprecated @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN notsup Unsupported engine for next@12.3.1: wanted: {"node":">=12.22.0"} (current: {"node":"12.18.3","npm":"6.14.7"})
npm WARN notsup Not compatible with your version of node/npm: next@12.3.1
翻译后:
@babel/polyfill@7.12.1:🚨该包已弃用,支持单独包含一个多边形和再生器运行时(当需要时)。更多信息请参见@babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill)。
npm WARN已弃用core-js@2.6.12: core-js@❤️.3不再维护,由于存在大量问题,不建议使用。由于V8引擎的奇思怪想,旧的core-js版本的特性检测可能会导致减速高达100倍,即使没有任何polyfilled。请将您的依赖项升级到core-js的实际版本。
npm WARN notsup不支持引擎next@12.3.1: wanted: {“node”:“>=12.22.0”}(当前:{“node”:“12.18.3”,“npm”:“6.14.7”})
与你的node/npm版本不兼容:next@12.3.1
解决:
尝试1:升级core-js
npm i core-js@latest
发现没有什么用
尝试2:
搜索发现@babel/polyfill已经弃用,执行 npm uninstall @babel/polyfill
提交最新的package.json
发现构建还是失败……
但是报错变成了其他:
npm WARN notsup Unsupported engine for next@12.3.1: wanted: {"node":">=12.22.0"} (current: {"node":"12.18.3","npm":"6.14.7"})
npm WARN notsup Not compatible with your version of node/npm: next@12.3.1
npm ERR! Unexpected end of JSON input while parsing near '...9e1TEhiY7BZKUWCe5VVR/'
尝试3:
报错变了,怀疑是包之间的依赖版本有问题,决定重新装下依赖
删掉node_modules
npm i rimraf -g
安装rimraf
打开node_modelus文件所在位置的cmd,输入 rimraf node_modules
,快速删除node_modules
再删除package-lock.json, yarn-lock.json
执行 npm i
, 重新装一遍依赖,把新生成的package-lock.json文件重新提交代码
打包构建,成功了!问题解决