简体   繁体   English

Electron 带 Strapi,找不到模块 package.json

[英]Electron with strapi, Cannot find module package.json

I built an application using strapi , i am trying to package it inside electron using electron-builder.我使用strapi构建了一个应用程序,我正在尝试使用电子生成器在 electron 内部 package 它。

The packaging is done well, but when i start the app, it shows this message包装做得很好,但是当我启动应用程序时,它会显示此消息

PS E:\Development\DentalSystem\dentalBE_test\dist\win-unpacked>
(node:13196) UnhandledPromiseRejectionWarning: Error: Cannot find module 'E:\Development\DentalSystem\dentalBE_test\dist\win-unpacked\package.json'
Require stack:
- E:\Development\DentalSystem\dentalBE_test\dist\win-unpacked\resources\app\node_modules\strapi\lib\Strapi.js
- E:\Development\DentalSystem\dentalBE_test\dist\win-unpacked\resources\app\node_modules\strapi\lib\index.js
- E:\Development\DentalSystem\dentalBE_test\dist\win-unpacked\resources\app\index.js
-
    at Module._resolveFilename (internal/modules/cjs/loader.js:797:17)
    at Function.o._resolveFilename (electron/js2c/browser_init.js:281:679)
    at Module._load (internal/modules/cjs/loader.js:690:27)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at new Strapi (E:\Development\DentalSystem\dentalBE_test\dist\win-unpacked\resources\app\node_modules\strapi\lib\Strapi.js:94:21)
    at module.exports (E:\Development\DentalSystem\dentalBE_test\dist\win-unpacked\resources\app\node_modules\strapi\lib\Strapi.js:564:18)
    at createWindow (E:\Development\DentalSystem\dentalBE_test\dist\win-unpacked\resources\app\index.js:23:5)
(node:13196) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13196) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

What seems to be the problem is that my application is looking to package.json file inside the root folder (directly relative to the exe file), while it exist inside the (app) folder with all other resources of the system.问题似乎是我的应用程序正在寻找根文件夹内的 package.json 文件(直接相对于 exe 文件),而它与系统的所有其他资源一起存在于 (app) 文件夹中。

this is my package.json file这是我的 package.json 文件

{
  "name": "DentalSys",
  "main": "./index.js",
  "version": "0.2.0",
  "description": "Dental Clinic Management System",
  "productName": "DentalSys",
  "build": {
    "appId": "com.kldoon.dentalSys",
    "asar": false    
  },
  "scripts": {
    "develop": "strapi develop",
    "strapi-start": "strapi start",
    "strapi-prod": "cross-env NODE_ENV=production npm start",
    "strapi-build": "strapi build",
    .....
  },
  "devDependencies": {
    "concurrently": "^5.1.0",
    "electron": "^9.1.2",
    "electron-builder": "^22.4.1",
    ......
  },
  "dependencies": {
    "knex": "0.20.13",
    "moment": "^2.27.0",
    "sqlite3": "^4.1.1",
    "strapi": "3.0.0-beta.17.5",
    .......
}

And this is my electron (index.js) file这是我的 electron (index.js) 文件

const { app, BrowserWindow, Menu, dialog } = require('electron')
const path = require("path");

const strapi = require('strapi');
//const { exec } = require("child_process");

function createWindow() {

    // Create the browser window.
    const win = new BrowserWindow({
        maximizable: true,
        title: "Dental System",
        webPreferences: {
            nodeIntegration: true
        }
    })
    win.maximize();

    strapi().start().then(() => {
        win.loadURL('http://localhost:49862/');
    }).catch((e) => {
        console.log(e);
    });

    win.on('closed', () => {
        app.quit();
    })
}

app.whenReady().then(createWindow)

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})

app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
        createWindow()
    }
})

I tried multiple solutions but none work, i hope someone can help with it.我尝试了多种解决方案,但都没有奏效,希望有人能提供帮助。

Thanks in advance.提前致谢。

It turned out to be easy fix, with dir option of strapi constructor结果很容易修复,带有strapi构造函数的dir选项

strapi({
dir: __dirname + '/'     ///<==== add this 
}).start().then(() => {
  win.loadURL('http://localhost:1337/');
}).catch((e) => {
  dialog.showMessageBox(win, { message: JSON.stringify(e) });
  console.log(e);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 电子找不到模块 package.json - electron cannot find module package.json 错误:找不到模块“../../package.json” - Error: Cannot find module '../../package.json' Openshift部署错误:找不到模块package.json - Openshift deploy error: Cannot find module package.json GCP Cloud Functions 在我的 package.json 中“找不到模块‘express’” - GCP Cloud Functions "Cannot find module 'express'" when it IS in my package.json 无法推送到 Heroku:找不到模块“node-linux-x64/package.json” - Unable to push to Heroku: Cannot find module 'node-linux-x64/package.json' 错误:即使在 package.json 中列出,也找不到模块“ejs” - Error: Cannot find module 'ejs' even though it's listed in package.json 为什么 Heroku 告诉我它在我的模块中找不到 package.json 当我执行 Z3115FB307DFCB5BA733BZ76 时 - Why is Heroku telling me it cannot find a package.json in my module when I do a heroku push Google Cloud Functions 错误:“找不到模块‘sharp’”,但它在我的 package.json 中 - Google Cloud Functions error: "Cannot find module 'sharp'" but it's in my package.json 当它同时位于package.json和node_modules中时,“找不到模块” - “Cannot Find Module”, when it is both in package.json and node_modules 错误:找不到模块'@angular-devkit/build-angular/package.json' - Error: Cannot find module '@angular-devkit/build-angular/package.json'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM