[英]Why is the installation of Babel failing in Electron? And do I need Babel or not?
我想使用npm软件包https://www.npmjs.com/package/swipe-detect并收到以下错误消息
export default function(target, callback, threshold=150) {
^^^^^^
SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:776:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:851:10)
at Module.load (internal/modules/cjs/loader.js:701:32)
at tryModuleLoad (internal/modules/cjs/loader.js:633:12)
at Function.Module._load (internal/modules/cjs/loader.js:625:3)
at Module.require (internal/modules/cjs/loader.js:739:19)
at require (internal/modules/cjs/helpers.js:14:16)
at Object.<anonymous> (C:\Users\folder\main.js:22:22)
at Module._compile (internal/modules/cjs/loader.js:839:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:851:10)
我发现错误是因为这是ES6语法。 因此,我一直在尝试根据本教程安装babel。 https://www.robinwieruch.de/minimal-node-js-babel-setup/ ,但出现错误消息
npm WARN deprecated @babel/polyfill@7.4.4: 🚨 As of Babel 7.4.0, this
npm WARN deprecated package has been deprecated in favor of directly
npm WARN deprecated including core-js/stable (to polyfill ECMAScript
npm WARN deprecated features) and regenerator-runtime/runtime
npm WARN deprecated (needed to use transpiled generator functions):
npm WARN deprecated
npm WARN deprecated > import "core-js/stable";
npm WARN deprecated > import "regenerator-runtime/runtime";
我还尝试了其他一些教程,并在.babelrc中设置环境。 错误消息仍然弹出。
现在,我了解到Babel已包含在Electron中。 为什么在电子项目中需要Babel 。
我一直在搜索两天,找不到解决方案。 为什么会弹出此错误?
根据您的Electron / Node版本,使用--experimental-modules
参数可能足以使其工作。 (但是, 当您尝试打包应用程序时 ,可能会出现问题 。)
有关在Electron中使用ES模块的一些背景信息,请参见https://github.com/electron/electron/issues/12011 。 在该线程中似乎建议了各种变通办法。
(鉴于您所需的库只有100行 ,并且在一个不错的Liberty MIT许可证下,克隆它,将默认值放在该文件末尾并仅导出该类可能会更容易。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.