Electron打包报错:The main entry point to your app was not found. Make sure "index.js" exists and does not get ignored by your ignore option
的解决方案!
最近开始从零接触Electron,为了做跨平台的GUI,学习后从https://github.com/electron/electron-quick-start-typescript下载一个入门库,也很简单的实现了npm start,但文档缺没说明如何打包,由于electron官方是js,没有过多的ts介绍,所以在打包上废了很多劲,可以看一下package.json:
{
"name": "electron-quick-start-typescript",
"version": "1.0.0",
"description": "A minimal Electron application written with Typescript",
"main": "dist/main.js",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"lint": "eslint -c .eslintrc --ext .ts ./src",
"start": "npm run build && electron ./dist/main.js",
"pack": "electron-packager ./ myapp --platform=win32 x64"
},
"repository": "https://github.com/electron/electron-quick-start-typescript",
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo",
"typescript"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"electron": "^17.1.2",
"electron-packager": "^15.4.0",
"eslint": "^7.32.0",
"typescript": "^4.5.5"
}
}
第11行的pack是我自己加的,写在这里方便在控制台用npm pack进行简化的调用,避免每次都敲那么多:
"pack": "electron-packager ./ myapp --platform=win32 x64"
但是会提示:“The main entry point to your app was not found. Make sure "index.js" exists and does not get ignored by your ignore option”这种鬼问题,各种搜索也没搜到,然后我开始蒙了……是的,我开始“瞎蒙了”,然后蒙对了:
1. 解决方案
就是加入了第5行的:
"main": "dist/main.js",
我是怎么蒙对的呢?报错提示找不到entry就是入口,但是后面神马“index.js”是个啥鬼,明明应该是找main才对,然后我的main.ts会编译成main.js,所以我猜那应该是想找main.js,所以卸载了第5行,之后在控制台切到工程根目录下,输入npm pack,打包就生效了,exe就打包成功了!
所以,提问:为什么github那个仓库没有这句配置呢?编译已经把js放到dist/main.js了,但打包却不指向,还要我自己猜着写一行配置,真坑。
希望可以帮助到正在死磕这个打包报错问题的朋友们!
|