realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.72k stars 564 forks source link

Can't load binary when containerised #6150

Open muddy-alex opened 11 months ago

muddy-alex commented 11 months ago

How frequently does the bug occur?

Always

Description

Node cant find binary file when containerised in Docker.

Investigating the container, the generated directory does not exist.

Seems to be similar to #5799

npx prebuild-install --runtime napi
prebuild-install warn This package does not support N-API version undefined
prebuild-install warn install connect ECONNREFUSED 127.0.0.1:80
npm notice 
npm notice New major version of npm available! 8.19.4 -> 10.1.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.1.0
npm notice Run npm install -g npm@10.1.0 to update!
npm notice 

Stacktrace & log output

node:internal/modules/cjs/loader:1028
  const err = new Error(message);
              ^

Error: Cannot find module '../generated/ts/realm.node'
Require stack:
- /app/node_modules/realm/dist/bundle.node.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15)
    at Function.Module._load (node:internal/modules/cjs/loader:873:27)
    at Module.require (node:internal/modules/cjs/loader:1100:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/app/node_modules/realm/dist/bundle.node.js:110:22)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Module.require (node:internal/modules/cjs/loader:1100:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/app/node_modules/realm/dist/bundle.node.js' ]
}

Can you reproduce the bug?

Always

Reproduction Steps

FROM node:16-alpine
RUN apk add --no-cache libc6-compat git make g++ libressl-dev

...build steps
...run steps

Inside the container

/app/node_modules/realm # tree
.
├── RealmJS.podspec
├── dependencies.list
├── dist
│   ├── bundle.d.ts
│   ├── bundle.node.js
│   ├── bundle.node.js.map
│   ├── bundle.react-native.js
│   └── bundle.react-native.js.map
├── index.node.js
├── index.react-native.js
├── node_modules
├── package.json
├── react-native
│   ├── android
│   │   ├── build.gradle
│   │   ├── gradle
│   │   │   └── wrapper
│   │   │       ├── gradle-wrapper.jar
│   │   │       └── gradle-wrapper.properties
│   │   ├── gradlew
│   │   ├── gradlew.bat
│   │   ├── settings.gradle
│   │   └── src
│   │       └── main
│   │           ├── AndroidManifest.xml
│   │           ├── java
│   │           │   └── io
│   │           │       └── realm
│   │           │           └── react
│   │           │               ├── RealmReactModule.java
│   │           │               ├── RealmReactPackage.java
│   │           │               └── util
│   │           │                   └── SSLHelper.java
│   │           └── jniLibs
│   │               ├── arm64-v8a
│   │               │   └── librealm.so
│   │               ├── armeabi-v7a
│   │               │   └── librealm.so
│   │               ├── x86
│   │               │   └── librealm.so
│   │               └── x86_64
│   │                   └── librealm.so
│   └── ios
│       ├── RealmReact
│       │   ├── RealmReact.h
│       │   ├── RealmReact.mm
│       │   └── RealmReact.xcconfig
│       └── realm-js-ios.xcframework
│           ├── Info.plist
│           ├── ios-arm64
│           │   ├── Headers
│           │   │   └── realm-js-ios
│           │   │       └── jsi_init.h
│           │   └── librealm-js-ios.a
│           ├── ios-arm64_x86_64-maccatalyst
│           │   ├── Headers
│           │   │   └── realm-js-ios
│           │   │       └── jsi_init.h
│           │   └── librealm-js-ios.a
│           └── ios-arm64_x86_64-simulator
│               ├── Headers
│               │   └── realm-js-ios
│               │       └── jsi_init.h
│               └── librealm-js-ios.a
├── react-native.config.js
├── realm-constants.json
├── scripts
│   └── submit-analytics.mjs
└── types.d.cts

31 directories, 38 files

Version

12.1.0

What services are you using?

Both Atlas Device Sync and Atlas App Services

Are you using encryption?

No

Platform OS and version(s)

Linux/Alpine Docker (linux/amd64)

Build environment

No response

Cocoapods version

No response

kneth commented 11 months ago

@muddy-alex Thank you for reporting. Indeed it looks like npx prebuild-install --runtime napi is not downloading the binary files. We need to investigate it in order to understand the situation.

muddy-alex commented 11 months ago

Appreciated. I'll be back on this later in the week so I'll report back any findings.

muddy-alex commented 9 months ago

We have since moved to node:buster-18 (away from node:16-alpine) for our base image and can confirm that the app is now running correctly.

kneth commented 9 months ago

@muddy-alex Actually I don't think it is caused by containerization, but the fact that Alpine is using Mucl and not glibc. Recently we have done some changes to Realm Core to make it support Mucl.

I leave the issue open as a reminder to us that we should produce Mucl compatible binaries as Alpine is very popular in cloud environments.

muddy-alex commented 9 months ago

Thanks for your support on these issues @kneth