gpt4 book ai didi

javascript - 为什么在 Electron 中安装 Babel 失败?我是否需要通天塔?

转载 作者:行者123 更新时间:2023-12-03 12:28:23 24 4
gpt4 key购买 nike

我想使用 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 中。 Why is Babel needed in an Electron project .

我已经找了两天了,找不到解决办法。为什么会弹出这个错误?

最佳答案

根据您的 Electron/Node 版本,使用 --experimental-modules争论可能足以让它发挥作用。 (但是可能有 issues when you try to package your app 。)

https://github.com/electron/electron/issues/12011了解在 Electron 中使用 ES 模块的一些背景知识。该线程中似乎提出了各种解决方法。

(假设您想要的库是 only 100 lines ,并且在良好的自由 MIT 许可证下,克隆它可能更容易,在该文件的末尾删除默认值,然后简单地导出类。)

关于javascript - 为什么在 Electron 中安装 Babel 失败?我是否需要通天塔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57196869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com