标签:md useBuiltIns cli babel js 报错 polyfill runtime
目录
升级后编译报错@babel/polyfill
is deprecated
缘由
-
升级
HBuilder X
版本到2.7.5.20200519
-
按照191031 - 部分手机出现或低版本Chrome异常"object.assign is not a function".md 进行修改
- 参考"解决方案5:[√有效的 最终采用的方案] - 修改uniapp-cli 编译工具的源码"
- 打开
HBuilderX\Bin\plugins\uniapp-cli\babel.config.js
- 修改
useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
为useBuiltIns: 'entry'
-
然后开始编译项目
-
结果出现错误信息
错误信息详情
13:31:24.838 请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。
13:31:24.844 正在编译中...
13:31:26.474 INFO Starting development server...
13:31:30.105 `@babel/polyfill` is deprecated. Please, use required parts of `core-js`
13:31:30.110 and `regenerator-runtime/runtime` separately
13:31:41.245 文件查找失败:'@babel/polyfill' at main.js:1
相关线索
-
通过对比工具对比2个新旧文件夹
HBuilderX\Bin\update\backup\plugins
HBuilderX\Bin\plugins
-
发现
plugins\uniapp-cli\package.json
里有"引用的类库"版本变更了- "@vue/cli-plugin-babel": "3.5.1",升级到了
"~4.2.0",
- "caniuse-lite": "^1.0.30001038", 升级到了
"^1.0.30001061"
- "@dcloudio/vue-cli-plugin-uni": "^2.0.0-26820200330001",升级到了
27520200518001
- "@vue/cli-plugin-babel": "3.5.1",升级到了
-
plugins\uniapp-cli\node_modules\@babel\plugin-transform-runtime\lib\index.js
if (has(options, "useBuiltIns")) { if (options.useBuiltIns) { throw new Error("The 'useBuiltIns' option has been removed. The @babel/runtime " + "module now uses builtins by default."); } else { throw new Error("The 'useBuiltIns' option has been removed. Use the 'corejs'" + "option to polyfill with `core-js` via @babel/runtime."); } } if (has(options, "polyfill")) { if (options.polyfill === false) { throw new Error("The 'polyfill' option has been removed. The @babel/runtime " + "module now skips polyfilling by default."); } else { throw new Error("The 'polyfill' option has been removed. Use the 'corejs'" + "option to polyfill with `core-js` via @babel/runtime."); } } if (has(options, "moduleName")) { throw new Error("The 'moduleName' option has been removed. @babel/transform-runtime " + "no longer supports arbitrary runtimes. If you were using this to " + "set an absolute path for Babel's standard runtimes, please use the " + "'absoluteRuntime' option."); }
-
plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\lib\h5\index.js
const beforeCode = (useBuiltIns === 'entry' ? 'import \'@babel/polyfill\';' : '') + `import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';`
-
Browser Compatibility | Vue CLI
f the dependency ships ES5 code, but uses ES6+ features without explicitly listing polyfill requirements (e.g. Vuetify): Use
useBuiltIns: 'entry'
and then addimport 'core-js/stable'; import 'regenerator-runtime/runtime';
to your entry file. This will import ALL polyfills based on yourbrowserslist
targets so that you don't need to worry about dependency polyfills anymore, but will likely increase your final bundle size with some unused polyfills.
解决方案
- 打开
plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\lib\h5\index.js
- 修改
const beforeCode = (useBuiltIns === 'entry' ? 'import \'@babel/polyfill\';' : '') +
- 为
const beforeCode = (useBuiltIns === 'entry' ? 'import \'core-js/stable\'; import \'regenerator-runtime/runtime\';' : '') +
标签:md,useBuiltIns,cli,babel,js,报错,polyfill,runtime
来源: https://www.cnblogs.com/AsionTang/p/12966128.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。