javascript - Electron 找不到模块/资源/应用程序/index.js

标签 javascript node.js npm electron

我是 electron 的新手,并且制作了我的第一个 electron 应用程序,它正常运行 npm start 但是当使用 npm run 我无法执行我的应用程序。 (我正在运行 ubuntu linux)cli 在运行可执行文件时给出此错误消息:

A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module '/home/user/Documents/dev/cocoa/cocoa-linux-x64/resources/app/index.js'
    at Module._resolveFilename (module.js:455:15)
    at Function.Module._resolveFilename (/home/user/Documents/dev/cocoa/cocoa-linux-x64/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:403:25)
    at Object.<anonymous> (/home/user/Documents/dev/cocoa/cocoa-linux-x64/resources/electron.asar/browser/init.js:171:8)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)

这是我的 package.json :

{
  "name": "cocoa",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron main.js",
    "package-linux" : "electron-packager . --platform=linux --arch=x64 --electron-version=1.4.13"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron-packager": "^8.7.1"
  }
}

这是 main.js 文件:

const electron = require('electron')
const {app, BrowserWindow} = electron

app.on('ready', ()=> {
  let win = new BrowserWindow({
    width:400,
    height:400
  })
  win.loadURL('http://google.com')
})

有谁知道我做错了什么,谢谢你的帮助。

最佳答案

好吧,那真的很愚蠢。我将项目的主要 js 文件命名为 main.js,而实际上它必须命名为 index.js 问题解决了!

关于javascript - Electron 找不到模块/资源/应用程序/index.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44731801/

相关文章:

Javascript:如何检查 DropDownList 是否被禁用

javascript - 使用php和ajax、js从数据库中删除

node.js - Google 云存储 API 和 Node.js

node.js - meteor node.js最新版

angular - Typescript - 代码无法从错误 TS1128 : Declaration or Statement expected, 生成,但在我提供代码时按预期运行

javascript - jquery可排序,如何防止列表移动到其他连接列表

javascript - face-api 和 tensorflow.js 在浏览器中不起作用

node.js - 如何使用 ImageMagick 或 GraphicsMagick Node.js 从图像中获取哈希值?

node.js - redis 保存session等数据

npm - `npm install @babel/cli` 表示四个模块为 "WARN deprecated"。我该如何解决这些弃用问题?