简体   繁体   中英

SPAWN node ENOENT error in electron package on run

I have build an node.js, express.js app, electron app and in operating system Windows . I have packaged the electron app through the tutorial: How to package an electron app

The packaging to win32 is successful without any warning or errors.
However when I try to run the app.exe file from the dist folder, though the main application window shows up but I cannot see any content that I have in my express.js app folder.
My app folder structure is:

app-root<br>
  - express-app
    - bin
      - www
    - node_modules
    - public
    - routes
    - views
    - app.js
    - package.json
  - node_modules
  - build
  - index.html
  - main.js
  - package.json
  - start-electron.js
  - dist<br>

Now The node.js, express.js app in electron runs smoothly normally before packaging. The app does not run from the exe file after packaging.

This is the error in console for the package .exe file:

events.js:163 Uncaught Error: spawn node ENOENT
at exports._errnoException (util.js:1050:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:367:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)

I have the SPAWN function in the index.html as:

  spawn = require("child_process").spawn,
  app = require('electron').remote.app,
  node = spawn("node", ["./express-app/bin/www"], {
    cwd: app.getAppPath()
  })

Any kind of help will be appreciated.

I have found a solution that does not require SPAWN, in an application with Node.js, Express.js and Electron. And works perfectly well even after packaging the electron app.

Here is the link to its GitHub repository:

GitHub repository for the solution's boilerplate.

One thing to remember is that after packaging the electron app through third party packagers like electron-builder it is necessary to put the config.json file into the new distribution/dist folder where the packaged files are present otherwise it throws the config.json not found error on the application execution.

You can use the following code using exec :

const exec = require('child_process').exec;
const node = exec("path/to/node " + app.getAppPath() + 'YOUR_APP', (err, stdout) => {console.log(stdout)});

path/to/node in my case => /usr/local/bin/node

It works perfectly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM