electron 安装import_Electron ES6 module import

在使用Electron 3.0.0-beta.1时遇到导入模块的问题,尝试通过client协议注册并加载模块,但收到错误提示。解决方案包括设置正确的MIME类型、将tsconfig.json中的目标设置为es5,或者使用protocol.registerBufferProtocol注册协议并确保路径正确,支持标准和安全模式。
摘要由CSDN通过智能技术生成

问题

Electron 3.0.0-beta.1

Node 10.2.0

Chromium 66.0.3359.181

The problem I'm having is importing a module. I created the following protocol:

protocol.registerFileProtocol('client', (request, callback) => {

var url = request.url.substr(8);

callback({path: path.join(__dirname, url)});

});

The output of the protocol is the correct path

"/Users/adviner/Projects/Client/src/ClientsApp/app.js"

I have the following module app.js with the following code:

export function square() {

return 'hello';

}

in my index.html I import the module like so:

import square from 'client://app.js';

console.log(square());

But I keep getting the error:

app.js/:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值