WonderInventions / node-webrtc

node-webrtc is a Node.js Native Addon that provides bindings to WebRTC M98
Other
120 stars 9 forks source link

Cannot run/not properly installed in docker image #16

Open medemi68 opened 5 months ago

medemi68 commented 5 months ago

Hi Guys,

I am creating a docker image for a project that I am working on, and the docker file gets built correctly. However, when it goes to run, it spits out an error saying that it can't find the binary. Something is not working correctly

Dockerfile:

FROM --platform=linux/amd64 node:20-bullseye

WORKDIR /root
COPY package.json /root/package.json
COPY package-lock.json /root/package-lock.json

RUN apt-get update
RUN apt install -y cmake build-essential python-is-python3 pkg-config clang gn ninja-build
RUN apt-get install ffmpeg -y

RUN npm install --location=global @nestjs/cli
RUN npm install --location=global patch-package
RUN npm install

COPY . /root/

CMD nest start

Output when run:

nestjs-1    | 
nestjs-1    | /root/node_modules/@roamhq/wrtc/lib/binding.js:24
nestjs-1    |   throw new Error(`Could not find wrtc binary on any of the paths: ${paths_to_try}`);
nestjs-1    |         ^
nestjs-1    | Error: Could not find wrtc binary on any of the paths: ../build-linux-x64/wrtc.node,../build-linux-x64/Debug/wrtc.node,../build-linux-x64/Release/wrtc.node,@roamhq/wrtc-linux-x64
nestjs-1    |     at Object.<anonymous> (/root/node_modules/@roamhq/wrtc/lib/binding.js:24:9)
nestjs-1    |     at Module._compile (node:internal/modules/cjs/loader:1358:14)
nestjs-1    |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
nestjs-1    |     at Module.load (node:internal/modules/cjs/loader:1208:32)
nestjs-1    |     at Function.Module._load (node:internal/modules/cjs/loader:1024:12)
nestjs-1    |     at Module.require (node:internal/modules/cjs/loader:1233:19)
nestjs-1    |     at require (node:internal/modules/helpers:179:18)
nestjs-1    |     at Object.<anonymous> (/root/node_modules/@roamhq/wrtc/lib/index.js:23:5)
nestjs-1    |     at Module._compile (node:internal/modules/cjs/loader:1358:14)
nestjs-1    |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1416:10)

Any help would be much appreciated. I would also like to note that I have it working outside of Docker.

duvallj commented 5 months ago

What do your package.json and package-lock.json files look like? This is a known issue that I think should be fixed in the next release (sorry about that taking so long oops), just making sure nothing is out-of-the-ordinary there

kkingsbe commented 2 months ago

I am also experiencing this. Here is my package.json:

{
  "name": "test-peer",
  "version": "1.0.0",
  "description": "",
  "main": "jest.config.js",
  "scripts": {
    "build": "tsc",
    "start": "node dist/index.js",
    "dev": "ts-node src/index.ts",
    "test": "jest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
  },
  "dependencies": {
    "@roamhq/wrtc": "^0.8.0",
    "@types/node": "^22.5.1",
    "@types/webrtc": "^0.0.43",
    "socket.io-client": "^4.7.5",
    "ts-results-es": "^4.2.0",
    "@types/jest": "^29.5.12",
    "jest": "^29.7.0",
    "ts-jest": "^29.2.5",
    "ts-node": "^10.9.2",
    "typescript": "^5.5.4"
  }
}
duvallj commented 2 months ago

@kkingsbe it looks like you have the version that includes the docker search path fix I thought would work, darn...

I'm guessing you might be building this docker image on an ARM64 host? What happens if you add an explicit dependency on @roamhq/wrtc-linux-x64. Not too experienced in figuring out why docker isn't picking up the right binary sorry

kkingsbe commented 2 months ago

I ended up finding a workaround to just not use docker for now (was trying to debug an issue relating to ICE connection discovery and wanted to see if it was due to being on the same NAT, hence the need for Docker :). Ended up just finding another way to resolve it)

DavidGOrtega commented 3 weeks ago

Hi, I suffered the same but the error is a bit misleading. I made the error more realistic adding a console.log in @roamhq/wrtc/lib/binding.js

let succeeded = false;
for (const path of paths_to_try) {
  try {
    console.log(path)   
    module.exports = require(path);
    console.log(module.exports, 'here')
    succeeded = true;
    break;
  } catch (error) {
    console.log(error)
  }
}

after that I saw that I had an error with a library

Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /workspace/node_modules/@roamhq/wrtc-linux-x64/wrtc.node)
duvallj commented 3 weeks ago

Ah! Thanks for debugging that @DavidGOrtega.

As explained in https://github.com/WonderInventions/node-webrtc/issues/21#issuecomment-2334871875, I've been having trouble getting libwebrtc to use a lower GLIBC version, due to its use of a bundled compiler toolchain. For now I would recommend using a different Docker base image as the simplest path forward for anyone having trouble with this.

DavidGOrtega commented 3 weeks ago

as a reference node:18-bookworm-slim is apparently compatible. I need to do some tests but at least the code runs.

DavidGOrtega commented 2 weeks ago

Effectively node:18-bookworm-slim is working perfectly.