5、(plugin uglify) Error: Unexpected token: name «key», expected: punc «;»
[!] (plugin uglify) Error: Unexpected token: name «key», expected: punc «;»
SyntaxError: Unexpected token: name «key», expected: punc «;»
at JS_Parse_Error.get (eval at <anonymous> (/Users/~/Documents/fe-module/demo/node_modules/rollup-plugin-uglify/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:71:23)
at reportError (/Users/~/Documents/fe-module/demo/node_modules/jest-worker/build/workers/processChild.js:107:11)
at reportClientError (/Users/~/Documents/fe-module/demo/node_modules/jest-worker/build/workers/processChild.js:87:10)
- 原因:
1、uglify-js 只支持压缩es5,不支持es6压缩。
2、原文描述: *Note: uglify-js is able to transpile only es5 syntax. If you want to transpile es6+ syntax use [terser](https://github.com/TrySound/rollup-plugin-terser) instead*
- 解决方案:
1、先用@rollup/plugin-babel 将es6转为es5再压缩。
2、使用rollup-plugin-terser压缩。
4、core-js/modules/es6.regexp.match (imported by src/test/base.js)
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
core-js/modules/es6.regexp.match (imported by src/test/base.js)
core-js/modules/es6.array.index-of (imported by src/test/base.js)
core-js/modules/es6.regexp.to-string (imported by src/test/util.js)
core-js/modules/es6.date.to-string (imported by src/test/util.js)
core-js/modules/es6.object.to-string (imported by src/test/util.js)
core-js/modules/es6.regexp.split (imported by src/test/android.js,
3、Plugin node-resolve: preferring built-in module 'process' over local alternative .....
(!) Plugin node-resolve: preferring built-in module 'process' over local alternative at '/Users/~/Documents/fe-module/demo/node_modules/process/index.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
(!) Plugin node-resolve: preferring built-in module 'util' over local alternative at '/Users/~/Documents/fe-module/demo/node_modules/util/util.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
(!) Plugin node-resolve: preferring built-in module 'buffer' over local alternative at '/Users/~/Documents/fe-module/demo/node_modules/buffer/index.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
- 原因:
@rollup/plugin-node-resolve 给出警告,如果为true,则插件将首先查找内置模块(例如fs、path)。如果为false,则插件将查找本地安装的同名模块。
- 解决方案:
建议显示的书写下,preferBuiltins: true
2、 /Users/~/Documents/fe-module/demo/node_modules/rollup/dist/shared/loadConfigFile.js:478
> @sdk@1.0.0 rollup /Users/~/Documents/fe-module/demo
> rollup --config build/rollup/rollup.config.js
/Users/~/Documents/fe-module/demo/node_modules/rollup/dist/shared/loadConfigFile.js:478
? (await import(url.pathToFileURL(fileName).href)).default
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:152:10)
at Module._compile (module.js:605:28)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Module.require (module.js:585:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/~/Documents/fe-module/demo/node_modules/rollup/dist/bin/rollup:22:25)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @sdk@1.0.0 rollup: `rollup --config build/rollup/rollup.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @sdk@1.0.0 rollup script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/~/.npm/_logs/2020-10-20T09_41_23_702Z-debug.log
- 原因:
从v2.0.0+ 开始不再支持node 8。
- 解决方案:
升级更高版本的 node
1、You have passed an unrecognized option
(!) You have passed an unrecognized option
Unknown input options: globals. Allowed options: acorn, acornInjectPlugins, cache, context, experimentalCacheExpiry, external, inlineDynamicImports, input, manualChunks, moduleContext, onwarn, perf, plugins, preserveEntrySignatures, preserveModules, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch
- 原因:
该层级非法的配置项。
- 解决方案:
globals属性存在output配置中。
参考文献
1、https://github.com/rollup/rollup/pull/3472