我想使用电子生成器使用打字稿构建一个电子应用程序。构建本身可以运行,但是启动app.exe会出现以下错误:“无法在模块外部使用import语句”
我猜我的package.json或tsconfig.json出了点问题。尝试了所有我能找到的,同样的错误。这是我当前的配置:
package.json:
{
"main": "./src/main.ts",
"type": "module",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"lint": "tslint -c tslint.json -p tsconfig.json",
"start": "npm run build && electron ./dist/main.js",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null"
},
"devDependencies": {
"@types/node": "^12.12.7",
"electron": "^8.1.0",
"electron-builder": "^22.3.2",
"tslint": "^5.19.0",
"typescript": "^3.6.0"
},
"dependencies": {
"@types/jquery": "^3.3.31",
"jquery": "^3.4.1",
"jquery-ui-dist": "^1.12.1",
"node-rest-client": "^3.1.0"
},
"build": {......},
"postinstall": "electron-builder install-app-deps"
}
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"suppressImplicitAnyIndexErrors": true,
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"removeComments": true,
"preserveConstEnums": true,
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"]
}
},
"include": [
"src/**/*"
],
"exclude": [ "node_modules" ]
}
答案 0 :(得分:-1)
我找到了解决方案:我划分了输出目录: /出纱启动过程 / dist用于纱线dist处理
别忘了将ts文件中的所有路径更改为/ out目录