Angular + Electron - Не удается найти основной модуль. js - PullRequest
0 голосов
/ 30 мая 2020

Я пытаюсь создать приложение macOs, используя электрон, запустив electron-packager . --platform=darwin

Он создает приложение, но при запуске выдает следующую ошибку

Uncaught Exception:
Error: Cannot find module '/Users/msaadbashir/Downloads/Angular/accounting/accounting-darwin-x64/accounting.app/Contents/Resources/app/main.js'
    at Module._resolveFilename (internal/modules/cjs/loader.js:797:17)
    at Function../lib/common/reset-search-paths.ts.Module._resolveFilename (electron/js2c/browser_init.js:7736:16)
    at Object.<anonymous> (electron/js2c/browser_init.js:6116:37)
    at Object../lib/browser/init.ts (electron/js2c/browser_init.js:6124:30)
    at __webpack_require__ (electron/js2c/browser_init.js:20:30)
    at electron/js2c/browser_init.js:84:18
    at electron/js2c/browser_init.js:87:10
    at NativeModule.compile (internal/bootstrap/loaders.js:287:5)
    at NativeModule.compileForPublicLoader (internal/bootstrap/loaders.js:222:8)
    at loadNativeModule (internal/modules/cjs/helpers.js:23:9)

Я сделал следующее кроме установки электрона.

индекс. html <base href="./">

основной. js

const { app, BrowserWindow } = require('electron')
let win;
function createWindow() {
    win = new BrowserWindow({
        width: 600,
        height: 600,
        backgroundColor: '#ffffff', 
    })
    win.loadFile('./dist/accounting/index.html')
    win.on('closed',function() {
        win = null
    })
}
app.on('ready',createWindow)
app.on('window-all-closed',function() {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})
app.on('activate',function() {
    if (win === null) {
        createWindow()
    }
})

пакет. json

{
  "name": "accounting",
  "version": "0.0.0",
  "main": "main.js",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "electron": "electron .",
    "electron-build": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.0.6",
    "@angular/cdk": "^9.2.4",
    "@angular/common": "~9.0.6",
    "@angular/compiler": "~9.0.6",
    "@angular/core": "~9.0.6",
    "@angular/forms": "~9.0.6",
    "@angular/localize": "~9.0.6",
    "@angular/material": "^9.2.4",
    "@angular/platform-browser": "~9.0.6",
    "@angular/platform-browser-dynamic": "~9.0.6",
    "@angular/router": "~9.0.6",
    "@ng-bootstrap/ng-bootstrap": "^6.1.0",
    "@ng-select/ng-select": "^4.0.0",
    "@ngx-loading-bar/core": "^4.2.0",
    "@ngx-loading-bar/http-client": "^4.2.0",
    "@ngx-loading-bar/router": "^4.2.0",
    "bootstrap": "^4.5.0",
    "e-ngx-print": "^5.3.1",
    "html2canvas": "^1.0.0-rc.5",
    "html2pdf.js": "^0.9.2",
    "jquery": "^3.5.1",
    "jspdf": "^1.5.3",
    "ng2-date-picker": "^9.0.0",
    "ngx-bootstrap": "^5.6.1",
    "ngx-infinite-scroll": "^9.0.0",
    "ngx-mask": "^9.0.2",
    "ngx-toastr": "^12.0.1",
    "rxjs": "^6.5.5",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.6",
    "@angular/cli": "~9.0.6",
    "@angular/compiler-cli": "~9.0.6",
    "@angular/language-service": "~9.0.6",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "electron": "^9.0.0",
    "electron-packager": "^14.2.1",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~5.18.0",
    "typescript": "~3.7.5"
  }
}

1 Ответ

1 голос
/ 30 мая 2020

Вам необходимо:

  • установить base-href в папку root npm run electron-build -- --base-href ./
  • обязательно main.js в root
  • убедитесь, что в главном поле package.json указан правильный путь к main.js
...