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轉(zhuǎn)為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焚刚,則插件將首先查找內(nèi)置模塊(例如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