oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
12.08k stars 438 forks source link

Linter: unable to run in node alpine #1736

Closed samcarton closed 9 months ago

samcarton commented 10 months ago

Error

Similar to #1690 but this is on an alpine docker image.

 > [2/2] RUN npx oxlint@latest --quiet:
#5 1.003 npm WARN exec The following package was not found and will be installed: oxlint@0.0.21
#5 1.436 /root/.npm/_npx/f4a33d9b4519ccab/node_modules/oxlint/bin/oxlint:37
#5 1.436     throw result.error;
#5 1.436     ^
#5 1.436
#5 1.436 Error: spawnSync /root/.npm/_npx/f4a33d9b4519ccab/node_modules/@oxlint/linux-x64/oxlint ENOENT
#5 1.436     at Object.spawnSync (node:internal/child_process:1117:20)
#5 1.436     at Object.spawnSync (node:child_process:876:24)
#5 1.436     at Object.<anonymous> (/root/.npm/_npx/f4a33d9b4519ccab/node_modules/oxlint/bin/oxlint:21:43)
#5 1.436     at Module._compile (node:internal/modules/cjs/loader:1356:14)
#5 1.436     at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
#5 1.436     at Module.load (node:internal/modules/cjs/loader:1197:32)
#5 1.436     at Module._load (node:internal/modules/cjs/loader:1013:12)
#5 1.436     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
#5 1.436     at node:internal/main/run_main_module:28:49 {
#5 1.436   errno: -2,
#5 1.436   code: 'ENOENT',
#5 1.436   syscall: 'spawnSync /root/.npm/_npx/f4a33d9b4519ccab/node_modules/@oxlint/linux-x64/oxlint',
#5 1.436   path: '/root/.npm/_npx/f4a33d9b4519ccab/node_modules/@oxlint/linux-x64/oxlint',
#5 1.436   spawnargs: [ '--quiet' ]
#5 1.436 }

Minimal repro

dockerfile:

FROM node:18-alpine
RUN npx oxlint@latest --quiet

docker build .

Boshen commented 10 months ago

Can you directly call /root/.npm/_npx/f4a33d9b4519ccab/node_modules/@oxlint/linux-x64/oxlint and see what the error is?

You may also install the binary from github releases (under assets): https://github.com/oxc-project/oxc/releases

samcarton commented 10 months ago

I tried running directly and kept getting not found errors. Apparently this happens due to dynamic link failures in alpine. adding gcompat seemed to fix it in my project, though in this repro it still panics, though maybe that's expected if you run it without anything to actually lint?

FROM node:18-alpine
RUN apk add gcompat
ENV RUST_BACKTRACE=full
RUN npx oxlint@latest --quiet

output:

#6 [3/3] RUN npx oxlint@latest --quiet
#6 sha256:f44c592b1972dfcde6c56db5070b79eed323f47df61f290c1a69b4d16d74dd3b
#6 1.352 npm WARN exec The following package was not found and will be installed: oxlint@0.0.21
#6 2.827 thread 'main' panicked at library/alloc/src/raw_vec.rs:534:5:
#6 2.827 capacity overflow
#6 2.827 stack backtrace:
#6 2.827    0:     0x7f1f98f90e9f - <unknown>
#6 2.827    1:     0x7f1f98c9021c - <unknown>
#6 2.827    2:     0x7f1f98f5f43d - <unknown>
#6 2.827    3:     0x7f1f98f925ce - <unknown>
#6 2.827    4:     0x7f1f98f92194 - <unknown>
#6 2.827    5:     0x7f1f98f9318c - <unknown>
#6 2.827    6:     0x7f1f98f92c78 - <unknown>
#6 2.827    7:     0x7f1f98f92c06 - <unknown>
#6 2.827    8:     0x7f1f98f92bf1 - <unknown>
#6 2.827    9:     0x7f1f98c010b4 - <unknown>
#6 2.827   10:     0x7f1f98c7a8ce - <unknown>
#6 2.827   11:     0x7f1f98c4f33e - <unknown>
#6 2.827   12:     0x7f1f98c439c3 - <unknown>
#6 2.827   13:     0x7f1f98c5105f - <unknown>
#6 2.827   14:     0x7f1f995c06d1 - <unknown>
#6 2.840 npm notice
#6 2.840 npm notice New patch version of npm available! 10.2.3 -> 10.2.5
#6 2.840 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.2.5>
#6 2.840 npm notice Run `npm install -g npm@10.2.5` to update!
#6 2.840 npm notice
#6 DONE 2.9s
Boshen commented 10 months ago

RUN npx oxlint@latest --quiet this feels like running the linter on the entire file system?

samcarton commented 10 months ago

Even against a single file I get some inconsistent behaviour

FROM node:18-alpine
# RUN apk add libc6-compat
RUN apk add gcompat 
RUN echo "namespace foo {}" > test.ts
ENV RUST_BACKTRACE=full
RUN npx --yes oxlint@latest --max-warnings 0 test.ts

When I run docker build . --progress plain --no-cache multiple times, sometimes it outputs the panic as above, sometimes it doesn't - but it doesn't seem to output the expected oxlint output.

#7 [4/4] RUN npx --yes oxlint@latest --max-warnings 0 test.ts
#7 sha256:15d4b9ebbd3ea1f5bb5fd1ec5a250d7454dab28aae915df7ec4c4a7a906f57b4
#7 2.413 npm notice
#7 2.413 npm notice New patch version of npm available! 10.2.3 -> 10.2.5
#7 2.414 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.2.5>
#7 2.414 npm notice Run `npm install -g npm@10.2.5` to update!
#7 2.414 npm notice
#7 DONE 2.5s

when I run $ npx --yes oxlint test.ts locally against the same file I get this, as expected

  ⚠ typescript-eslint(no-namespace): ES2015 module syntax is preferred over namespaces.
   ╭─[test.ts:1:1]
 1 │ namespace foo {}
   · ─────────
   ╰────
  help: Replace the namespace with an ES2015 module or use `declare module`

Finished in 6ms on 1 file with 70 rules using 16 threads.
Found 1 warning and 0 errors.
RiESAEX commented 9 months ago

For ENOENT problem, I think we need to build x86_64-unknown-linux-musl for Alpine. I have seen similar issues in biome and swc, and they were both solved by a musl build.

Boshen commented 9 months ago

0.2.3-alpha.0 contains https://www.npmjs.com/package/@oxlint/linux-x64-musl

I'm not sure if it works :-/

FutureExcited commented 9 months ago

+1, just worked and fixed my Docker build

thank god

EDIT: nvm, not working.

Boshen commented 9 months ago

With the latest oxlint v0.2.5? So it's not a musl / glibc problem 🤔

RiESAEX commented 9 months ago

wired. It works for me on node:18-alpine. image image

FutureExcited commented 9 months ago

Seems like it's shadcn-vue issue. In their repo they had troubles with it as well. I just used previous version of their app and it worked.

ENK0DED commented 9 months ago

I think for this issue to be resolved completely, you have to give oxc-parser the same treatment as oxlint in #2126.

It seems like the bindings of oxc-parser are needed in this case, not oxlint, as mentioned in the title of radix-vue/shadcn-vue#293.

Boshen commented 9 months ago

Moving oxc-parser to a seperate issue: https://github.com/oxc-project/oxc/issues/2195

I'll close this issue for now, feel free to open another one with more information.

I'll also update the error messages: https://github.com/oxc-project/oxc/issues/2196