最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SPAWN node ENOENT error in electron package on run - Stack Overflow

programmeradmin5浏览0评论

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 _binedTickCallback (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 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 _binedTickCallback (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.

Share Improve this question edited Aug 14, 2017 at 8:33 echology asked Aug 14, 2017 at 6:04 echologyechology 3972 gold badges3 silver badges15 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

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

发布评论

评论列表(0)

  1. 暂无评论