screenshot-desktop icon indicating copy to clipboard operation
screenshot-desktop copied to clipboard

Electron (Packaged): Windows 10 spawn ENOENT error

Open byfareska opened this issue 5 years ago β€’ 17 comments

I'm getting something like that but on Windows 10 (on ubuntu works fine). https://stackoverflow.com/questions/17951133/spawn-enoent-error

I've switched from 1.7.0 to 1.6.1 and it works on both OS.

byfareska avatar Apr 23 '19 15:04 byfareska

I am also having the same error after packaging the app..

I did revert back to 1.6.1 but still no luck.

Check environment variable and it has "C:\WINDOWS\system32\cmd.exe" in the path variable.

any pointer as to how to resolve this issue?

Thanks Rex

rexn8r avatar Jul 12 '19 07:07 rexn8r

@rexn8r what do you mean by packaging the app?

bencevans avatar Jul 12 '19 11:07 bencevans

when i create app package using electron-packager and run the exe with asar file, the plugin throws the error.

If i run the electron app in development environment i.e. using npm start command from node.js command window, the plug-in works absolutely fine.

the package folder structure created by electron-packager is:

app.exe -- resources (folder) ---|__ (under resource folder) app.asar (all the app files are packaged in it with html, javascript, node modules etc)

i unpacked the asar file and node module folder did have the screen-shot files. so its not that the packager is missing files.

any help would be appreciated.

thanks rex

rexn8r avatar Jul 12 '19 12:07 rexn8r

There was a fix conducted for Electron in https://github.com/bencevans/screenshot-desktop/releases/tag/v1.5.5. I'm not much doing much with Electron so this isn't a priority for me. However if you work out a fix a pull requested would be very welcome.

bencevans avatar Jul 12 '19 12:07 bencevans

I managed to fix this issue in my project using electron-forge by adding the "asar" => "unpack" option in the packager config:

{
  "name": "myproject",
  "version": "1.0.0",
  "description": "mydescription",
  "main": "main.js",
  "scripts": { ...  },
  "keywords": [ ...  ],
  "author": "me",
  "license": "ISC",
  "devDependencies": { ... },
  "dependencies": { ... },
  "config": {
    "forge": {
      "packagerConfig": {
        "asar": {
          "unpack": "**/node_modules/screenshot-desktop/lib/win32/{app.manifest,screenCapture_1.3.2.bat}"
        }
      },
      "makers": [ ... ]
    }
  }
}

Not sure if and how this can be applied to this projects package.json directly.

Edit: Added the missing "app.manifest" file which needs to be unpacked as well.

ForsakenNGS avatar Jul 21 '19 18:07 ForsakenNGS

@tance77 has submitted a PR which aims to fix this (thanks!). I don't really have anything to test it with as no longer work with any Electron apps. Would someone in this thread be up for reviewing #152?

bencevans avatar Nov 28 '19 12:11 bencevans

I am using electron-builder to package my application. According to electron-builder documentation, "Node modules, that must be unpacked, will be detected automatically, you don’t need to explicitly set asarUnpack", however screenshot-desktop is not detected by electron-builder so I added this configuration to package.json, and the problem is solved.

  "build" {
    ...
    "asarUnpack": [
      "node_modules/screenshot-desktop/lib/win32"
    ]
  }

Very similar to the solution proposed by @ForsakenNGS

MetinYarci avatar Sep 01 '20 19:09 MetinYarci

There seem to be quite a few duplicate issues being opened up which relate to this. If someone's available to, a review of PR #152 from someone more familiar than I with Electron would be appreciated.

bencevans avatar Oct 19 '20 13:10 bencevans

https://github.com/bencevans/screenshot-desktop/issues/135#issuecomment-513575121 https://github.com/bencevans/screenshot-desktop/issues/135#issuecomment-685074823

These two posts are exactly right. The .bat file needs to be unpacked along side for the packed version of the electorn app. The bat file can not be executed inside the app.asar file.

Additionally adding the files to your windows extra resources worked for me as well.

 "win": {
      "extraResources": [
        "node_modules/screenshot-desktop/lib/win32/screenCapture_1.3.2.bat",
        "node_modules/screenshot-desktop/lib/win32/app.manifest",
      ],
}

Many solutions to this problem.

The solution in #152 assumes the files to be unpacked along side the asar file

tance77 avatar Oct 19 '20 18:10 tance77

I'm getting the same problems after packing with https://github.com/vercel/pkg/

Error: spawn C:\Windows\system32\cmd.exe ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
    at onErrorNT (internal/child_process.js:468:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn C:\\Windows\\system32\\cmd.exe',
  path: 'C:\\Windows\\system32\\cmd.exe',
  spawnargs: [
    '/d',
    '/s',
    '/c',
    '""C:\\snapshot\\prod\\node_modules\\screenshot-desktop\\lib\\win32\\screenCapture_1.3.2.bat" "C:\\TEMP\\2020105-12416-11y7u3z.wzw.jpg" "'
  ],
  cmd: '"C:\\snapshot\\prod\\node_modules\\screenshot-desktop\\lib\\win32\\screenCapture_1.3.2.bat" "C:\\TEMP\\2020105-12416-11y7u3z.wzw.jpg" '
}

As suggested by @tance77 I configured pkg to include this 2 files:

"pkg": {
    "assets": [
      "node_modules/screenshot-desktop/lib/win32/screenCapture_1.3.2.bat",
      "node_modules/screenshot-desktop/lib/win32/app.manifest"
    ]
  },

I see that they are added from the build debug log, but I'm still getting the same error.

Update: As I learned that's a general problem with pkg as it does not allow such external processes: https://github.com/vercel/pkg/issues/342

somuelle-tmt avatar Nov 05 '20 08:11 somuelle-tmt

I don't understand what is the error cause? I tried the above solutions for building the application again with asar unpack but I think it's not working.

hmake98 avatar Nov 06 '20 14:11 hmake98

For me this is an issue, if I build the package without -asar it works, but all the source code is exposed πŸ˜• When using -asar it doesn't work.

promatik avatar Nov 27 '20 12:11 promatik

@MetinYarci thanks a lot it works in production

Ciberusps avatar Jan 06 '21 16:01 Ciberusps

I am using electron-builder to package my application. According to electron-builder documentation, "Node modules, that must be unpacked, will be detected automatically, you don’t need to explicitly set asarUnpack", however screenshot-desktop is not detected by electron-builder so I added this configuration to package.json, and the problem is solved.

  "build" {
    ...
    "asarUnpack": [
      "node_modules/screenshot-desktop/lib/win32"
    ]
  }

Very similar to the solution proposed by @ForsakenNGS

thanks.. it's work.

alsocodes avatar Jun 26 '21 08:06 alsocodes

Hi I am using this boilerplate https://github.com/michalzaq12/electron-nuxt for our app, wanted to know how and where we could add the asarunpack to explicitly unpack this module.

urvinsoneta avatar Jul 28 '21 17:07 urvinsoneta

im having this issue currently with https://github.com/vercel/pkg runs fine normaly but if you bundle it, the files are there but its not able to run the .bat file on windows πŸ‘Ž

si458 avatar Aug 26 '21 13:08 si458

please can everyone try my PR #225 i believe this will fix the issued with node bundlers like PKG πŸ‘ EDIT: PKG also detectes the path.join and includes the bat and manifest for you πŸ‘

si458 avatar Nov 08 '21 13:11 si458