yao-pkg / pkg

Package your Node.js project into an executable
https://www.npmjs.com/package/@yao-pkg/pkg
MIT License
312 stars 11 forks source link

uWebsocket.js - uws_win32_x64_115.node is not a valid Win32 application #18

Closed Talaar closed 7 months ago

Talaar commented 7 months ago

What version of pkg are you using?

5.11.1

What version of Node.js are you using?

20.10.0

What operating system are you using?

Win11

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node20-win-x64

Describe the Bug

I want to build a exe with hyper-express module that's use uWebsocket.js. PKG create the exe without problems but when i start the app then an error throws.

pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error: This version of uWS.js supports only Node.js LTS versions 16, 18 and 20 on (glibc) Linux, macOS and Windows, on Tier 1 platforms (https://github.com/nodejs/node/blob/master/BUILDING.md#platform-list).

Error: C:\Users\vue\AppData\Local\Temp\pkg\d39930fab4e8f21b85cb204c2b43f9f539f3d047edb43c9beb0968b09295438f\uWebSockets.js\uws_win32_x64_115.node is not a valid Win32 application.
C:\Users\vue\AppData\Local\Temp\pkg\d39930fab4e8f21b85cb204c2b43f9f539f3d047edb43c9beb0968b09295438f\uWebSockets.js\uws_win32_x64_115.node
    at C:\snapshot\build\node_modules\uWebSockets.js\uws.js:23:9
    at Object.<anonymous> (C:\snapshot\build\node_modules\uWebSockets.js\uws.js:25:3)
    at Module._compile (pkg/prelude/bootstrap.js:1930:22)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\snapshot\build\node_modules\hyper-express\index.js:4:21)

Node.js v20.10.0

package.json

"pkg": {
    "assets": [
      "static/**/*",
      "node_modules/uWebSockets.js/**/*x64*"
    ],
    "targets": [
      "node20-win-x64"
    ]
  }

Expected Behavior

App starts correctly

To Reproduce

main.zip esbuild version of the main.ts

robertsLando commented 7 months ago

Tried with node 18? Does that throws too?

Talaar commented 7 months ago

I tried node 16 and 18, same problem. Start the main.js in terminal with "node main.js" work fine.

robertsLando commented 7 months ago

No clue I'm sorry, you should check what check uWebsocket does in order to trigger that error and once you find it write a patch for that file so it doesn't throw on packaged version. I did this for many packages

Talaar commented 7 months ago

Hm ... it's only a require

uws.js

module.exports = (() => {
    try {
        return require('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node');
    } catch (e) {
        throw new Error('This version of uWS.js supports only Node.js LTS versions 16, 18 and 20 on (glibc) Linux, macOS and Windows, on Tier 1 platforms (https://github.com/nodejs/node/blob/master/BUILDING.md#platform-list).\n\n' + e.toString());
    }
})();
robertsLando commented 7 months ago

@Talaar yeah but that's a dinamic require, that's why it is failing... see project readme

TLDR;: add uws_win32_x64_115.node to assets