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

Could not resolve lightningcss.linux-arm64-gnu.node in Docker with M1 #335

Closed
humphd opened this issue Nov 9, 2022 · 14 comments · Fixed by #342
Closed

Could not resolve lightningcss.linux-arm64-gnu.node in Docker with M1 #335

humphd opened this issue Nov 9, 2022 · 14 comments · Fixed by #342

Comments

@humphd
Copy link

humphd commented Nov 9, 2022

I'm not sure if this belongs in Parcel or here, but I'll start here and you can correct me.

It seems like trying to use lightningcss inside Docker on an M1 Mac fails to do the right thing with the binary dependencies (not sure if M1 is related or not, but that's what I'm using). I've made a demo repo to show the problem.

If I do npm run build natively on my M1 Mac, it works. However, inside Docker, the build gives this:

❯ docker build . -t parcel-bug
[+] Building 21.3s (9/9) FINISHED
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 116B                                       0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 34B                                           0.0s
 => [internal] load metadata for docker.io/library/node:16.18.1-bullseye   0.3s
 => [1/5] FROM docker.io/library/node:16.18.1-bullseye@sha256:7fb41fa8410  0.0s
 => [internal] load build context                                          0.0s
 => => transferring context: 329B                                          0.0s
 => CACHED [2/5] WORKDIR /app                                              0.0s
 => [3/5] COPY . .                                                         0.0s
 => [4/5] RUN npm i                                                       19.6s
 => ERROR [5/5] RUN npm run build                                          1.2s
------
 > [5/5] RUN npm run build:
#0 0.389
#0 0.389 > [email protected] build
#0 0.389 > parcel build index.html
#0 0.389
#0 0.819 Building...
#0 1.102 🚨 Build failed.
#0 1.104
#0 1.105 @parcel/transformer-css: Could not resolve module
#0 1.105 "/app/node_modules/lightningcss/lightningcss.linux-arm64-gnu.node" from
#0 1.105 "/app/node_modules/lightningcss/node/index.js"
#0 1.106
#0 1.106   Error: Could not resolve module
#0 1.106   "/app/node_modules/lightningcss/lightningcss.linux-arm64-gnu.node" from
#0 1.106   "/app/node_modules/lightningcss/node/index.js"
#0 1.106       at $0578d0f6e116167e$export$fb2a0b866a8162dc.resolve
#0 1.106   (/app/node_modules/@parcel/package-manager/lib/index.js:4991:21)
#0 1.106       at NodePackageManager.resolveSync
#0 1.106   (/app/node_modules/@parcel/package-manager/lib/index.js:3510:42)
#0 1.106       at NodePackageManager.requireSync
#0 1.106   (/app/node_modules/@parcel/package-manager/lib/index.js:3352:34)
#0 1.106       at Module.m.require
#0 1.106   (/app/node_modules/@parcel/package-manager/lib/index.js:3366:25)
#0 1.106       at require (node:internal/modules/cjs/helpers:103:18)
#0 1.106       at Object.<anonymous> (/app/node_modules/lightningcss/node/index.js:21:22)
#0 1.106       at Module._compile (node:internal/modules/cjs/loader:1155:14)
#0 1.106       at Object.Module._extensions..js
#0 1.106   (node:internal/modules/cjs/loader:1209:10)
#0 1.106       at Module.load (node:internal/modules/cjs/loader:1033:32)
#0 1.106       at NodePackageManager.load
#0 1.106   (/app/node_modules/@parcel/package-manager/lib/index.js:3375:15)
#0 1.108
------
ERROR: failed to solve: executor failed running [/bin/sh -c npm run build]: exit code: 1

Inside the container, I can see that it's pulled in what I think are the right dependencies:

/app/node_modules# ls lightningcss*
lightningcss:
LICENSE  README.md  node  package.json

lightningcss-linux-arm64-gnu:
README.md  lightningcss.linux-arm64-gnu.node  package.json

lightningcss-linux-arm64-musl:
README.md  lightningcss.linux-arm64-musl.node  package.json

Inside the container, node is using process.platform === 'linux' and process.arch === 'arm64'.

@devongovett
Copy link
Member

hmm seems like it should work based on the logic here https://github.com/parcel-bundler/lightningcss/blob/master/node/index.js. Can you log out parts in there?

@humphd
Copy link
Author

humphd commented Nov 9, 2022

Inside the container within node:

> let parts = [process.platform, process.arch];
undefined
> if (process.platform === 'linux') {
...   const { MUSL, family } = require('detect-libc');
...   if (family === MUSL) {
...     parts.push('musl');
...   } else if (process.arch === 'arm') {
...     parts.push('gnueabihf');
...   } else {
...     parts.push('gnu');
...   }
... } else if (process.platform === 'win32') {
...   parts.push('msvc');
... }
3
> parts
[ 'linux', 'arm64', 'gnu' ]

@humphd
Copy link
Author

humphd commented Nov 9, 2022

This looks like an issue with glibc versions in the base image of debian/node, which is unfortunate because 2.35 seems to only be in unstable:

> require(`lightningcss-${parts.join('-')}`)
Uncaught:
Error: /lib/aarch64-linux-gnu/libm.so.6: version `GLIBC_2.35' not found (required by /app/node_modules/lightningcss-linux-arm64-gnu/lightningcss.linux-arm64-gnu.node)
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1239:18)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18) {
  code: 'ERR_DLOPEN_FAILED'

Maybe we need to roll back to an earlier version of Parcel in Docker?

@humphd
Copy link
Author

humphd commented Nov 9, 2022

Reading the code, I wondered if I could bypass the requirement on glibc 2.35 and use WASM, but it fails too (maybe I don't understand how it should work):

CSS_TRANSFORMER_WASM=1 npm run build

> [email protected] build
> parcel build index.html

🚨 Build failed.

@parcel/transformer-css: Could not resolve module
"/app/node_modules/lightningcss/pkg" from
"/app/node_modules/lightningcss/node/index.js"

  Error: Could not resolve module "/app/node_modules/lightningcss/pkg" from
  "/app/node_modules/lightningcss/node/index.js"
      at $0578d0f6e116167e$export$fb2a0b866a8162dc.resolve
  (/app/node_modules/@parcel/package-manager/lib/index.js:4991:21)
      at NodePackageManager.resolveSync
  (/app/node_modules/@parcel/package-manager/lib/index.js:3510:42)
      at NodePackageManager.requireSync
  (/app/node_modules/@parcel/package-manager/lib/index.js:3352:34)
      at Module.m.require
  (/app/node_modules/@parcel/package-manager/lib/index.js:3366:25)
      at require (node:internal/modules/cjs/helpers:103:18)
      at Object.<anonymous> (/app/node_modules/lightningcss/node/index.js:16:20)
      at Module._compile (node:internal/modules/cjs/loader:1155:14)
      at Object.Module._extensions..js
  (node:internal/modules/cjs/loader:1209:10)
      at Module.load (node:internal/modules/cjs/loader:1033:32)
      at NodePackageManager.load
  (/app/node_modules/@parcel/package-manager/lib/index.js:3375:15)

It looks like I need to use musl vs. glibc until the node docker images use a version that matches what lightningcss needs. I managed to get it working by switching to Alpine instead of Debian, like so (this isn't optimized, but shows it will work):

FROM node:16.18.1-alpine as builder

# Parcel build needs a few things to work on alpine
RUN apk add --update --no-cache g++ make python3 && ln -sf python3 /usr/bin/python

WORKDIR /app
COPY . .
RUN npm i
RUN npm run build

###################################################################################

FROM nginx
COPY --from=builder /app/dist/ /usr/share/nginx/html/

I wonder if this is a documentation issue that should be fixed somehow? Now that Parcel has a dependency on the OS's C Library, you need to know what you're using and match it. This won't be obvious to lots of people.

@devongovett
Copy link
Member

devongovett commented Nov 9, 2022

hmm I don't think we have a strong dependency on that. what version of Parcel are you upgrading from?

might just be an artifact of how the binary was compiled. I'll have to look into it more

https://github.com/parcel-bundler/lightningcss/blob/master/.github/workflows/release.yml#L116

@humphd
Copy link
Author

humphd commented Nov 10, 2022

That's great, thanks as always, @devongovett! At least I have a work around until you do.

@jteppinette
Copy link

jteppinette commented Nov 10, 2022

I am currently unable to run parcel build in GitHub Actions (ubuntu-latest) with a package-lock generated from an M1 MacBook. I am receiving the same "could not resolve module ... lightningcss/lightningcss.linux-x64-gnu.node" error. I am assuming this is related.

Maybe Ref: npm/cli#4828 ?

@jteppinette
Copy link

I was able to resolve this error..... very weird....

Reproduction Steps:

  1. npm install lightningcss
  2. npm run build in cross platform (linux vs arm)
  3. success
  4. rm package-lock.json
  5. npm install
  6. npm run build in cross platform (linux vs arm)
  7. fails

I discovered that when running npm install after clearing the package-lock.json, all of the platform specific packages i.e. node_modules/lightningcss-linux-arm64-gnu are not added to package-lock like they are when doing a simple npm install lightningcss.

Can anyone shed light on this? Is this standard behavior?

@humphd
Copy link
Author

humphd commented Nov 10, 2022

In GitHub Actions, ubuntu-latest is currently using Ubuntu 20.04.5 LTS which is based on glibc 2.31. I wonder if you're hitting the same bug as I am inside Docker, with lightningcss wanting 2.35?

@CristhianF7
Copy link

Running yarn add lightningcss doesn't fix the issue. For some reason the optional dependencies are not being installed, I had to run yarn add lightningcss --ignore-platform to be able to see them (just for testing purposes). Also looking at the code it doesn't seem to point to the right path.

I couldn't see the platform files in the node_modules/lightningcss/ folder
Screenshot 2022-11-14 at 1 07 03 PM

I had to copy the files from the node_modules folder cp -R node_modules/lightningcss-linux-arm64-gnu/lightningcss.linux-arm64-gnu.node node_modules/lightningcss/ and now I'm getting this issue while building the app:

Error: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.29' not found (required by
/opt/app/node_modules/@parcel/transformer-js/parcel-swc.linux-arm64-gnu.node

Screenshot 2022-11-14 at 1 10 29 PM

Docker file:

# build
FROM --platform=linux/arm64 node:18 AS build

WORKDIR /opt/app

COPY package*.json ./

RUN yarn install
RUN yarn add lightningcss --ignore-platform

COPY ./ .

ENV PORT=3000

EXPOSE $PORT

RUN npm run build

@jacob-orbiit
Copy link

This issue occurs without anything fancy, just npm on Node.js v18.12.0, and it occurs on linux as well:

Console output (Node.js v18.12.0)
  const err = new Error(message);
              ^

Error: Cannot find module '../lightningcss.linux-x64-gnu.node'
Require stack:
- /…/node_modules/lightningcss/node/index.js
- /…/node_modules/esbuild-css-modules-plugin/lib/plugin.js
- /…/node_modules/esbuild-css-modules-plugin/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/…/node_modules/lightningcss/node/index.js:21:22)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/…/node_modules/lightningcss/node/index.js',
    '/…/node_modules/esbuild-css-modules-plugin/lib/plugin.js',
    '/…/node_modules/esbuild-css-modules-plugin/index.js'
  ]
}

image

@devongovett
Copy link
Member

I believe this was caused by an upstream commit to the base docker image we use to compile the ARM binaries, where Ubuntu was upgraded thereby causing GLIBC to be upgraded. I'm going to pin to an older version for now.

@devongovett
Copy link
Member

@CristhianF7 your issue is with a different module (parcel-swc). Also looks like maybe you are on an even older version of Ubuntu (maybe 18?). We compile on Ubuntu 20.04. You could try upgrading.

vipranarayan14 added a commit to vipranarayan14/samsaadhanii-concordance that referenced this issue Jul 19, 2023
What?
- Parcel start/build fails with error:
```
@parcel/transformer-css: Could not resolve module
"/workspaces/samsaadhanii-concordance/node_modules/lightningcss/lightningcss.linux-arm64-gnu.node"
from "/workspaces/samsaadhanii-concordance/node_modules/lightningcss/node/index.js"
```
- Guess it's most likely due to using linux docker image in macos (arm).
- Adding `lightningcss` explicity as dep resolves this error.

More details on this:
parcel-bundler/lightningcss#335
@NilsBaumgartner1994
Copy link

Fails on ubuntu latest

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

Successfully merging a pull request may close this issue.

6 participants