Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While using package with docker desktop #122

Open
deepakkatara opened this issue Apr 14, 2023 · 6 comments
Open

While using package with docker desktop #122

deepakkatara opened this issue Apr 14, 2023 · 6 comments

Comments

@deepakkatara
Copy link

HI Team,

On macOS, I use the snappy package, which is successful. however, the moment I attempt to launch the project locally using Docker Desktop, an issue occurs while starting the container-

`Error: Cannot find module '@napi-rs/snappy-linux-x64-musl'
Require stack:

  • /code/node_modules/snappy/index.js
  • /code/dist/server/index.js
  • /code/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Function.wrappedResolveFilename [as _resolveFilename] (/code/node_modules/newrelic/lib/shimmer.js:291:42)
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Function.wrappedLoad [as _load] (/code/node_modules/newrelic/lib/shimmer.js:307:24)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object. (/code/node_modules/snappy/index.js:1:2955)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/code/node_modules/snappy/index.js',
    '/code/dist/server/index.js',
    '/code/index.js'
    ]
    }`

The potential problem that I see is connected to optionalDependencies because it only installs @napi-rs/snappy-darwin-x64 compatible with Mac and searches for Linux @napi-rs dependencies when I run it in a docker container.

Docker info
image

What could be the potential solution of this?

@Brooooooklyn
Copy link
Owner

@deepakkatara you are supposed to re-install your dependencies in your docker environment

@deepakkatara
Copy link
Author

deepakkatara commented Apr 14, 2023

image

I also tried

-- Install snappy package using yarn and include Linux support
RUN yarn add snappy --build-from-source --frozen-lockfile --production=false -- --with-pic

@Brooooooklyn
Copy link
Owner

The COPY . . is after yarn install, so your installed node_modules in Docker is overridden by the host node_modules.

@eabrouwer3
Copy link

I'm getting the same issue, and I think it's because my local arch is different than the docker arch. So my package-lock.json file has this:

    "node_modules/snappy/node_modules/@napi-rs/snappy-darwin-arm64": {
      "version": "7.2.2",
      "cpu": [
        "arm64"
      ],
      "license": "MIT",
      "optional": true,
      "os": [
        "darwin"
      ],
      "engines": {
        "node": ">= 10"
      }
    },

while the Docker runtime (node:18-alpine) needs @napi-rs/snappy-linux-arm64-musl. But I only want to run npm ci in the docker container, not npm i. Maybe I could manually detect which one it needs and install that specific engine? Thoughts, @Brooooooklyn?

@Brooooooklyn
Copy link
Owner

@eabrouwer3 see npm/cli#4828

You can remove node_modules and package-lock.json and re-generate the package-lock.json

@eabrouwer3
Copy link

I ended up adding all of the runtimes as optional dependencies, so that no matter where I'm running npm ci from, I get all of them.

  "optionalDependencies": {
    "@napi-rs/snappy-android-arm-eabi": "~7.2.2",
    "@napi-rs/snappy-android-arm64": "~7.2.2",
    "@napi-rs/snappy-darwin-arm64": "~7.2.2",
    "@napi-rs/snappy-darwin-x64": "~7.2.2",
    "@napi-rs/snappy-freebsd-x64": "~7.2.2",
    "@napi-rs/snappy-linux-arm-gnueabihf": "~7.2.2",
    "@napi-rs/snappy-linux-arm64-gnu": "~7.2.2",
    "@napi-rs/snappy-linux-arm64-musl": "~7.2.2",
    "@napi-rs/snappy-linux-x64-gnu": "~7.2.2",
    "@napi-rs/snappy-linux-x64-musl": "~7.2.2",
    "@napi-rs/snappy-win32-arm64-msvc": "7.2.2",
    "@napi-rs/snappy-win32-ia32-msvc": "~7.2.2",
    "@napi-rs/snappy-win32-x64-msvc": "~7.2.2"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants