denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.21k stars 5.41k forks source link

uWebsocket with BYONM does not load native lib on Windows #25956

Open lucacasonato opened 2 months ago

lucacasonato commented 2 months ago

So how do i get uWebsocket insalled on deno 2.0.0-rc.8 - If at all possible I do not have any deno experience, just want to try it because nodeJS runs into strange GC issues under high load for that project.

Running deno install provides this message

deno install
error: Error in hyper-express@6.17.2 parsing version requirement for dependency "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.48.0"

Caused by:
    Package specified a dependency outside of npm (github:uNetworking/uWebSockets.js#v20.48.0). Deno does not install these for security reasons. The npm package should be improved to have all its dependencies on npm.

    To work around this, you can use a package.json and install the dependencies via `npm install`.

But using npm install will install the build for nodeJs. Resulting in the crash:

error: Uncaught (in promise) 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).

TypeError: LoadLibraryExW failed
    at file:///C:/Users/.../node_modules/uWebSockets.js/uws.js:22:9
    at Object.<anonymous> (file:///C:/Users/.../node_modules/uWebSockets.js/uws.js:24:3)
    at Object.<anonymous> (file:///C:/Users/.../node_modules/uWebSockets.js/uws.js:26:4)
    at Module._compile (node:module:748:34)
    at Object.Module._extensions..js (node:module:767:10)
    at Module.load (node:module:665:32)
    at Function.Module._load (node:module:537:12)
    at Module.require (node:module:684:19)
    at require (node:module:808:16)
    at Object.<anonymous> (file:///C:/Users/.../node_modules/hyper-express/index.js:4:21)

Originally posted by @BolverBlitz in https://github.com/denoland/deno/issues/25648#issuecomment-2384894168

BolverBlitz commented 2 months ago

OS: Microsoft Windows 11 Pro OS Version: 10.0.22631 Nicht zutreffend Build 22631 To replicate this error follow those steps:

Command: deno -A .\index.js

index.js

import { createRequire } from "node:module";
const require = createRequire(import.meta.url);

require('dotenv').config();
require('module-alias/register');

const os = require('node:os');
const packageJSON = require('@root/package.json');
const HyperExpress = require('hyper-express');

process.package = packageJSON;

const port = process.env.BALANCER_PORT || 80;

const app = new HyperExpress.Server({
    fast_buffers: process.env.HE_FAST_BUFFER == 'false' ? false : true || false,
});

app.get('/', (req, res) => {
    res.header('Content-Type', 'text/html');
    res.send(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Index</title><link rel="icon" href="data:image/x-icon;,"></head><body><h1>Deno Test Branch</h1><hr><i>Test/${process.package.version}@${os.hostname}</i></body></html>`)
})

app.set_error_handler((req, res, error) => {
    console.error(error);
});

app.listen(port)
    .then((socket) => process.log.system(`Listening on port: ${port}`))
    .catch((error) => process.log.error(`Failed to start webserver on: ${port}\nError: ${error}`));

package.json

{
    "name": "deno-test",
    "version": "0.0.1",
    "description": "",
    "main": "index.js",
    "scripts": {
      "start": "node index.js",
      "update": "npx npm-check-updates -u"
    },
    "author": "",
    "license": "MIT",
    "_moduleAliases": {
      "@root": ".",
      "@src": "./src",
      "@lib": "./lib",
      "@api": "./api",
      "@middleware": "./middleware",
      "@config": "./config"
    },
    "dependencies": {
      "dotenv": "^16.4.5",
      "hyper-express": "^6.16.4",
      "module-alias": "^2.2.3"
    }
  }

Its a code sniped of a larger nodejs project i tryed porting to deno following https://docs.deno.com/runtime/fundamentals/node/

nathanwhit commented 2 months ago

The issue causing the LoadLibraryExW error is that uWebSocket.js uses v8 APIs directly (which we don't support as it's not ABI stable).

SebastienGllmt commented 1 week ago

To work around this, you can use a package.json and install the dependencies via npm install.

Fixing that specific error (which is a subset of this issue) depends on #18478