oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.28k stars 2.77k forks source link

Error: Cannot find module 'detect-libc' #7729

Open ollecoffee opened 11 months ago

ollecoffee commented 11 months ago

What version of Bun is running?

bun install v1.0.18 (36c316a2)

What platform is your computer?

Github Actions

What steps can reproduce the bug?

Using astro :)

bun install v1.0.18 (36c316a2) node:internal/modules/cjs/loader:1137 throw err; ^

Error: Cannot find module 'detect-libc' Require stack:

What is the expected behavior?

https://github.com/ollegkz/olle.coffee/actions/runs/7259256409

What do you see instead?

https://github.com/ollegkz/olle.coffee/actions/runs/7259394812

Additional information

running bun install twice seems to solve it, see https://github.com/ollegkz/olle.coffee/commit/f32053cb2166ebf0d1c3e3f239e763401a2b6ea5

ollecoffee commented 11 months ago

Didn't help with two installs :( https://github.com/ollegkz/olle.coffee/actions/runs/7264836340

paperdave commented 11 months ago

this is a node.js stack trace. re-run with `bun --bun astro build

ollecoffee commented 11 months ago

So the solution is for withastro/action@v1 to use --bun? :) https://github.com/withastro/action/blob/main/action.yml#L93

zanhk commented 10 months ago

Same error as well, it happen sometimes, not consinstely

here's my workflow

name: Assertions and static report

on:
    workflow_dispatch:
    push:
        branches:
            - main

env:
    PRIVJS_TOKEN: ${{ secrets.PRIVJS_TOKEN }}

jobs:
    test-and-deploy:
        runs-on: ubuntu-latest
        timeout-minutes: 10
        steps:
            - uses: actions/checkout@v3

            - uses: oven-sh/setup-bun@v1
              with:
                  bun-version: latest

            - name: Install dependencies
              run: bun install

            - name: Install Global dependencies
              run: bun install -g netlify-cli @unlighthouse/cli puppeteer

            - name: Unlighthouse assertions and client
              run: unlighthouse-ci

            - name: Deploy
              run: netlify deploy --dir=.unlighthouse --prod --message="New Release Deploy from GitHub Actions"
              env:
                  NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
                  NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}

here the error stack:

Run bun install
bun install v1.0.22 (b400b3[6](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:7)c)
node:internal/modules/cjs/loader:113[7](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:8)
  throw err;
  ^

Error: Cannot find module 'detect-libc'
Require stack:
- /home/runner/work/majestico.it/majestico.it/node_modules/@vite-pwa/assets-generator/node_modules/sharp/install/libvips.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:1[8](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:9))
    at Object.<anonymous> (/home/runner/work/majestico.it/majestico.it/node_modules/@vite-pwa/assets-generator/node_modules/sharp/install/libvips.js:13:20)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:11[9](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:10)7:32)
    at Module._load (node:internal/modules/cjs/loader:[10](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:11)13:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/runner/work/majestico.it/majestico.it/node_modules/@vite-pwa/assets-generator/node_modules/sharp/install/libvips.js'
  ]
}

Node.js v18.19.0
node:internal/modules/cjs/loader:[11](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:12)37
  throw err;
  ^

Error: Cannot find module 'semver/functions/coerce'
Require stack:
- /home/runner/work/majestico.it/majestico.it/node_modules/@vite-pwa/assets-generator/node_modules/sharp/lib/libvips.js
- /home/runner/work/majestico.it/majestico.it/node_modules/@vite-pwa/assets-generator/node_modules/sharp/install/can-compile.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Module.require (node:internal/modules/cjs/loader:[12](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:13)25:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/home/runner/work/majestico.it/majestico.it/node_modules/@vite-pwa/assets-generator/node_modules/sharp/lib/libvips.js:10:22)
    at Module._compile (node:internal/modules/cjs/loader:[13](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:14)56:[14](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:15))
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
    at Module.require (node:internal/modules/cjs/loader:1225:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/runner/work/majestico.it/majestico.it/node_modules/@vite-pwa/assets-generator/node_modules/sharp/lib/libvips.js',
    '/home/runner/work/majestico.it/majestico.it/node_modules/@vite-pwa/assets-generator/node_modules/sharp/install/can-compile.js'
  ]
}

Node.js v[18](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:19).[19](https://github.com/majesticostudio/majestico.it/actions/runs/7532921476/job/20504464338#step:4:20).0

error: install script from "sharp" exited with 1
Error: Process completed with exit code 1.

Never got problems locally (yet)

ollecoffee commented 10 months ago

@zanhk I solved this by removing sharp from my package.json (as astro probably bundles another version) 👍

zanhk commented 10 months ago

thanks @ollegkz, but if I remove it the project stop building

Could not find Sharp. Please install Sharp (sharp) manually into your project or migrate to another image service.

21:52:09.791 | generating optimized images
-- | --
21:52:10.050 | [CouldNotTransformImage] Could not transform image `/_astro/yourProject.-bS8TTFK.png`. See the stack trace for more information.
21:52:10.050 | Hint:
21:52:10.051 | This is often caused by a corrupted or malformed image. Re-exporting the image from your image editor may fix this issue.
21:52:10.051 | Error reference:
21:52:10.051 | https://docs.astro.build/en/reference/errors/could-not-transform-image/
21:52:10.051 | Stack trace:
21:52:10.051 | at generateImageInternal (file:///opt/buildhome/repo/node_modules/astro/dist/assets/build/generate.js:129:21)
21:52:10.051 | at async file:///opt/buildhome/repo/node_modules/p-queue/dist/index.js:187:36
21:52:10.051 | Caused by:
21:52:10.052 | Could not find Sharp. Please install Sharp (`sharp`) manually into your project or migrate to another image service.
21:52:10.052 | at loadSharp (file:///opt/buildhome/repo/dist/chunks/astro/assets-service_O2gHAwmQ.mjs:289:11)
21:52:10.052 | at async generateImageInternal (file:///opt/buildhome/repo/node_modules/astro/dist/assets/build/generate.js:123:26)
21:52:10.052 | at async file:///opt/buildhome/repo/node_modules/p-queue/dist/index.js:187:36

https://docs.astro.build/en/reference/errors/missing-sharp/

zanhk commented 10 months ago

I will try installing the exact version astro currently use (0.32.6)

https://github.com/withastro/astro/blob/main/packages/astro/package.json#L182C5-L182C23

Edit: nvm, with older version it's not working https://github.com/lovell/sharp/issues/3511#issuecomment-1831891933

zanhk commented 10 months ago

Let's hope astro upgrade sharp version

riywo commented 10 months ago

In my case, bun 1.0.24 solved this issue. So, it might be good to try the latest bun version.

Failed with 1.0.23 on CodeBuild

                                 # Starting phase: preBuild
2024-01-20T06:51:31.856Z [INFO]: # Executing command: npm install -g bun@canary
2024-01-20T06:51:34.297Z [INFO]: added 3 packages in 2s
2024-01-20T06:51:34.315Z [INFO]: # Executing command: bun install --frozen-lockfile
2024-01-20T06:51:34.324Z [WARNING]: bun install v1.0.23 (3c785c88)
2024-01-20T06:51:37.171Z [WARNING]: node:internal/modules/cjs/loader:1147
                                    throw err;
                                    ^
                                    Error: Cannot find module 'semver/functions/coerce'
                                    Require stack:
                                    - /codebuild/output/src1450109756/src/opsbr.com/node_modules/astro/node_modules/sharp/install/libvips.js
                                    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
                                    at Module._load (node:internal/modules/cjs/loader:985:27)
                                    at Module.require (node:internal/modules/cjs/loader:1235:19)
                                    at require (node:internal/modules/helpers:176:18)
                                    at Object.<anonymous> (/codebuild/output/src1450109756/src/opsbr.com/node_modules/astro/node_modules/sharp/install/libvips.js:14:22)
                                    at Module._compile (node:internal/modules/cjs/loader:1376:14)
                                    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
                                    at Module.load (node:internal/modules/cjs/loader:1207:32)
                                    at Module._load (node:internal/modules/cjs/loader:1023:12)
                                    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {
                                    code: 'MODULE_NOT_FOUND',
                                    requireStack: [
                                    '/codebuild/output/src1450109756/src/opsbr.com/node_modules/astro/node_modules/sharp/install/libvips.js'
                                    ]
                                    }
                                    Node.js v20.11.0
2024-01-20T06:51:37.171Z [WARNING]: 
2024-01-20T06:51:37.172Z [WARNING]: error: install script from "sharp" exited with 1
2024-01-20T06:51:37.186Z [ERROR]: !!! Build failed
2024-01-20T06:51:37.188Z [ERROR]: !!! Non-Zero Exit Code detected

Succeeded with 1.0.24 on CodeBuild

2024-01-20T07:15:40.901Z [INFO]: # Starting phase: preBuild
                                 # Executing command: npm install -g bun@latest
2024-01-20T07:15:43.217Z [INFO]: added 3 packages in 2s
2024-01-20T07:15:43.228Z [INFO]: # Executing command: bun install --frozen-lockfile
2024-01-20T07:15:43.248Z [WARNING]: bun install v1.0.24 (6fa35839)
2024-01-20T07:15:48.234Z [INFO]: + @headlessui/tailwindcss@0.2.0
                                 + @tailwindcss/aspect-ratio@0.4.2
                                 + @tailwindcss/typography@0.
2024-01-20T07:15:48.241Z [INFO]: 5.10
                                 + @types/react@18.2.48
                                 + @typescript-eslint/eslint-plugin@6.19.0
                                 + @typescript-eslint/parser@6.19.0
                                 + eslint@8.56.0
                                 + eslint-config-prettier@9.1.0
                                 + eslint-plugin-astro@0.31.3
                                 + eslint-plugin-jsx-a11y@6.8.0
                                 + eslint-plugin-log-filenames@1.0.6
                                 + husky@8.0.3
                                 + lint-staged@15.2.0
                                 + npm-check-updates@16.14.12
                                 + prettier@3.2.4
                                 + prettier-plugin-astro@0.13.0
                                 + typescript@5.3.3
                                 + @astrojs/check@0.4.1
                                 + @astrojs/mdx@2.0.5
                                 + @astrojs/react@3.0.9
                                 + @astrojs/sitemap@3.0.5
                                 + @astrojs/tailwind@5.1.0
                                 + @headlessui/react@1.7.18
                                 + @heroicons/react@2.1.1
                                 + astro@4.2.1
                                 + astro-seo-meta@4.1.0
                                 + astro-seo-schema@4.0.0
                                 + iso-639-1@3.1.0
                                 + react@18.2.0
                                 + react-dom@18.2.0
                                 + sharp@0.33.2
                                 + tailwindcss@3.4.1
                                 997 packages installed [5.00s]
2024-01-20T07:15:48.241Z [WARNING]: warn: sharp's install script took 1.5s
2024-01-20T07:15:48.246Z [INFO]: # Completed phase: preBuild
zanhk commented 10 months ago

@riywo Thanks, will try

risu729 commented 7 months ago

We also faced this issue in several repositories. The conditions for reproduction are below.

Since astro has sharp@0.32.6 in its optionalDependencies, I guess somehow the postinstall script of sharp is executed before other packages are installed due to duplicating the same package with different versions.

For a workaround, we can move sharp to overrides from dependencies. Then, the postinstall script is executed correctly and does not cause the Cannot find module error. I tested this workaround over 100 times using a script but no errors were thrown. e.g. package.json

{
  "dependencies": {
    "astro": "4.5.10"
   },
  "overrides": {
    "sharp": "0.33.3"
   }
}
zanhk commented 7 months ago

Thanks @risu729 for the workaround

github-actions[bot] commented 3 months ago

This issue is stale and may be closed due to inactivity. If you're still running into this, please leave a comment.