簡體   English   中英

為什么Babel的安裝在Electron中失敗? 我是否需要通天塔?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM