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

Build error when Docker install bun starting from version >= 1.0.16 #7676

Closed
alvinchristian7 opened this issue Dec 15, 2023 · 3 comments
Closed
Labels
bug Something isn't working bun install Something that relates to the npm-compatible client docker An issue that occurs when running in Docker

Comments

@alvinchristian7
Copy link

alvinchristian7 commented Dec 15, 2023

What version of Bun is running?

1.0.18+36c316a24

What platform is your computer?

No response

What steps can reproduce the bug?

{
  "name": "kp-frontend",
  "version": "0.1.0",
  "private": true,
  "homepage": ".",
  "trustedDependencies": ["next-pwa", "sharp"],
  "scripts": {
    "dev": "env-cmd -f .env.dev next dev -p 1900",
    "staging": "env-cmd -f .env.staging next dev -p 1900",
    "prod": "env-cmd -f .env.prod next dev -p 1900",
    "build": "next lint --quiet && next build --no-lint",
    "build:nolint": "next build --no-lint",
    "build:local": "next lint --quiet && env-cmd -f .env.prod next build --no-lint",
    "start:local": "NEXT_SHARP_PATH=/node_modules/sharp next start",
    "start": "NEXT_SHARP_PATH=/node_modules/sharp next start -p 80",
    "lint": "next lint --quiet",
    "format": "prettier --write \"**/*.+(ts|tsx|js|jsx|json)\"",
    "prepare": "husky install",
    "test": "jest --watch",
    "test:ci": "jest --ci",
    "storybook": "start-storybook -p 1997",
    "build-storybook": "build-storybook"
  },
  "dependencies": {
    "@dnd-kit/core": "^6.0.8",
    "@dnd-kit/sortable": "^7.0.2",
    "@emotion/react": "^11.11.1",
    "@emotion/server": "^11.10.0",
    "@emotion/styled": "^11.10.6",
    "@fingerprintjs/fingerprintjs": "^4.0.0",
    "@livekit/components-react": "^1.0.4",
    "@livekit/components-styles": "^1.0.1",
    "@livekit/react-core": "^1.1.0",
    "@mantine/carousel": "6",
    "@mantine/core": "6",
    "@mantine/dates": "6",
    "@mantine/dropzone": "6",
    "@mantine/form": "6",
    "@mantine/hooks": "6",
    "@mantine/next": "6",
    "@react-pdf-viewer/core": "3.12.0",
    "@react-pdf-viewer/default-layout": "^3.12.0",
    "@react-pdf-viewer/full-screen": "^3.12.0",
    "@reactour/tour": "^3.3.0",
    "@reduxjs/toolkit": "^1.9.7",
    "@south-paw/react-vector-maps": "^3.2.0",
    "@supercharge/strings": "^2.0.0",
    "@tabler/icons-react": "^2.9.0",
    "@types/lodash": "^4.14.192",
    "@zoomus/websdk": "^2.16.0",
    "async-mutex": "^0.4.0",
    "axios": "^1.3.4",
    "bootstrap": "^5.3.0-alpha1",
    "clsx": "^2.0.0",
    "cookies-next": "^2.1.1",
    "crypto-js": "^4.1.1",
    "dayjs": "^1.11.7",
    "dexie": "^3.2.3",
    "dexie-react-hooks": "^1.1.3",
    "dnd-core": "^16.0.1",
    "dotenv": "^16.3.1",
    "echarts": "^5.4.3",
    "echarts-for-react": "^3.0.2",
    "embla-carousel-autoplay": "^7.1.0",
    "embla-carousel-react": "^7.1.0",
    "env-cmd": "^10.1.0",
    "firebase": "^9.17.2",
    "framer-motion": "^10.12.16",
    "html-react-parser": "^3.0.16",
    "immer": "^10.0.3",
    "immutability-helper": "^3.1.1",
    "jotai": "^2.0.3",
    "jsrsasign": "^10.6.1",
    "jwt-decode": "^3.1.2",
    "livekit-client": "^1.11.2",
    "livekit-server-sdk": "^1.2.1",
    "lodash": "^4.17.21",
    "moment": "^2.29.4",
    "moment-duration-format": "^2.3.2",
    "next": "13.2.1",
    "next-pwa": "^5.6.0",
    "next-redux-wrapper": "^8.1.0",
    "next-share": "^0.23.0",
    "nextjs-progressbar": "^0.0.15",
    "no-try": "^3.1.0",
    "nprogress": "^0.2.0",
    "pdfjs-dist": "3.4.120",
    "query-string": "^8.1.0",
    "react": "18.2.0",
    "react-awesome-reveal": "^4.2.3",
    "react-collapsed": "^4.0.4",
    "react-cookie": "^5.0.0",
    "react-dnd": "^16.0.1",
    "react-dnd-html5-backend": "^16.0.1",
    "react-dnd-touch-backend": "^16.0.1",
    "react-dom": "18.2.0",
    "react-draggable": "^4.4.5",
    "react-easy-crop": "^5.0.0",
    "react-error-boundary": "^4.0.9",
    "react-fast-marquee": "^1.6.0",
    "react-hot-toast": "^2.4.0",
    "react-icons": "^4.8.0",
    "react-iframe": "^1.8.5",
    "react-imask": "^6.4.3",
    "react-intersection-observer": "^9.5.2",
    "react-pageflip": "^2.0.3",
    "react-pdf": "^6.2.2",
    "react-player": "^2.12.0",
    "react-redux": "^8.0.5",
    "react-responsive-masonry": "^2.1.7",
    "react-sortablejs": "^6.1.4",
    "react-spring-bottom-sheet": "^3.4.1",
    "react-svg-polygon": "^2.0.6",
    "react-use-downloader": "^1.2.4",
    "recharts": "^2.5.0",
    "screenfull": "^6.0.2",
    "sharp": "0.33.0",
    "sortablejs": "^1.15.0",
    "validator": "^13.9.0",
    "wait": "^0.4.2",
    "yet-another-react-lightbox": "^3.11.3",
    "yup": "^1.0.2"
  },
  "devDependencies": {
    "@babel/core": "^7.21.0",
    "@commitlint/cli": "^17.4.4",
    "@commitlint/config-conventional": "^17.4.4",
    "@storybook/addon-actions": "^6.5.16",
    "@storybook/addon-essentials": "^6.5.16",
    "@storybook/addon-interactions": "^6.5.16",
    "@storybook/addon-links": "^6.5.16",
    "@storybook/builder-webpack5": "^6.5.16",
    "@storybook/manager-webpack5": "^6.5.16",
    "@storybook/react": "^6.5.16",
    "@storybook/testing-library": "^0.0.13",
    "@svgr/webpack": "^6.5.1",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^14.0.0",
    "@types/crypto-js": "^4.1.1",
    "@types/moment-duration-format": "^2.2.3",
    "@types/node": "18.14.2",
    "@types/react": "18.0.28",
    "@types/react-dom": "18.0.11",
    "@types/react-responsive-masonry": "^2.1.0",
    "@types/sortablejs": "^1.15.1",
    "@types/testing-library__jest-dom": "5.14.5",
    "@types/validator": "^13.7.14",
    "@typescript-eslint/eslint-plugin": "latest",
    "@typescript-eslint/parser": "latest",
    "babel-loader": "^8.3.0",
    "eslint": "latest",
    "eslint-config-next": "latest",
    "eslint-config-prettier": "latest",
    "eslint-config-standard-with-typescript": "latest",
    "eslint-plugin-import": "latest",
    "eslint-plugin-n": "latest",
    "eslint-plugin-prettier": "latest",
    "eslint-plugin-promise": "latest",
    "eslint-plugin-react": "latest",
    "eslint-plugin-react-hooks": "latest",
    "file-loader": "^6.2.0",
    "husky": "^8.0.3",
    "jest": "28.1.0",
    "jest-environment-jsdom": "28.1.0",
    "path": "^0.12.7",
    "prettier": "latest",
    "react-webcam": "^7.1.0",
    "sass": "^1.58.3",
    "storybook-addon-next": "^1.7.3",
    "storybook-addon-sass-postcss": "^0.1.3",
    "storybook-addon-state": "^1.0.3",
    "ts-dedent": "^2.2.0",
    "typescript": "^5.2.2"
  }
}

When i use above package.json and bun version >= 1.0.16, build successful from local device (my laptop environment). But failed to build over Docker using this Dockerfile:

FROM oven/bun:alpine AS dependencies
RUN apk update
RUN apk add bash git busybox-extras nano curl

WORKDIR /kp-web

COPY package.json ./
RUN bun install

FROM oven/bun:alpine AS builder

WORKDIR /kp-web

COPY . .
COPY .env.dev .env
COPY --from=dependencies /kp-web/node_modules ./node_modules
RUN bun build:nolint

FROM oven/bun:alpine AS runner
WORKDIR /kp-web
COPY --from=builder /kp-web/.env.dev ./.env
COPY --from=builder /kp-web/next.config.js ./
COPY --from=builder /kp-web/public ./public
COPY --from=builder /kp-web/.next ./.next
COPY --from=builder /kp-web/node_modules ./node_modules
COPY --from=builder /kp-web/package.json ./package.json

EXPOSE 80
CMD ["bun", "start"]

What is the expected behavior?

Build successfully till finish

What do you see instead?

BUILD LOG FROM JENKINS
............
#15 3.729 info  - Creating an optimized production build...
#15 5.227 > [PWA] Compile server
#15 5.232 > [PWA] Compile server
#15 5.329 > [PWA] Compile client (static)
#15 5.329 > [PWA] Auto register service worker with: /kp-web/node_modules/next-pwa/register.js
#15 5.329 > [PWA] Service worker: /kp-web/public/sw.js
#15 5.329 > [PWA]   url: /sw.js
#15 5.329 > [PWA]   scope: /
#15 260.0 
#15 260.0 > Build error occurred
#15 260.0 57 |         if (breakingChangeIndex >= 0) {
#15 260.0 58 |             body = body.slice(0, breakingChangeIndex);
#15 260.0 59 |         }
#15 260.0 60 |         message = (message.moduleName ? (0, _stripAnsi).default(message.moduleName) + '\n' : '') + (message.file ? (0, _stripAnsi).default(message.file) + '\n' : '') + body + (message.details && verbose ? '\n' + message.details : '') + (filteredModuleTrace && filteredModuleTrace.length ? (importTraceNote || '\n\nImport trace for requested module:') + filteredModuleTrace.map((trace)=>`\n${trace.moduleName}`).join('') : '') + (message.stack && verbose ? '\n' + message.stack : '');
#15 260.0 61 |     }
#15 260.0 62 |     let lines = message.split('\n');
#15 260.0                      ^
#15 260.0 TypeError: message.split is not a function. (In 'message.split("\n")', 'message.split' is undefined)
#15 260.0       at formatMessage (/kp-web/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.js:62:17)
#15 260.0       at /kp-web/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.js:12:16
#15 260.0       at map (:1:21)
#15 260.0       at formatWebpackMessages (/kp-web/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.js:10:29)
#15 260.0       at /kp-web/node_modules/next/dist/build/webpack-build.js:204:36
#15 260.0       at traceFn (/kp-web/node_modules/next/dist/trace/trace.js:72:20)
#15 260.0       at /kp-web/node_modules/next/dist/build/webpack-build.js:203:14
#15 260.0       at processTicksAndRejections (:61:77)
#15 260.0 
#15 ERROR: process "/bin/sh -c bun build:nolint" did not complete successfully: exit code: 1
...........

Additional information

Build error when Docker install bun starting from version >= 1.0.16, should i include all of my packages into "trustedDependencies" or some packages need to be updated because they are not compatible with newer bun versions similar to this issue ? I'm really clueless to debug this kind of thing, so i need your help guys. Thanks

@alvinchristian7 alvinchristian7 added the bug Something isn't working label Dec 15, 2023
@mikesprague
Copy link

mikesprague commented Dec 15, 2023

I'm seeing similar behavior. A discord.js bot builds fine with bun locally, but when built inside a Docker image (to be deployed to fly.io) it fails with the following:

 => CACHED [base 2/5] RUN npm install --location=global npm bun                                                                                                                                                           
 => CACHED [base 3/5] WORKDIR /usr/src/app                                                                                                                                                                                
 => CACHED [base 4/5] COPY ./package.json ./                                                                                                                                                                              
 => CACHED [base 5/5] COPY ./bun.lockb ./                                                                                                                                                                                 
 => ERROR [dev 1/2] RUN bun install                                                                                                                                                                                       
------
 > [dev 1/2] RUN bun install:
#0 0.307 bun install v1.0.18 (36c316a2)
#0 3.913 node:internal/modules/cjs/loader:1147
#0 3.913   throw err;
#0 3.913   ^
#0 3.913
#0 3.913 Error: Cannot find module '/usr/src/app/install.js'
#0 3.913     at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
#0 3.913     at Module._load (node:internal/modules/cjs/loader:985:27)
#0 3.913     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
#0 3.913     at node:internal/main/run_main_module:28:49 {
#0 3.913   code: 'MODULE_NOT_FOUND',
#0 3.913   requireStack: []
#0 3.913 }
#0 3.913
#0 3.913 Node.js v20.10.0
#0 3.913
#0 3.913 error: postinstall script from "bun" exited with code 1 (SIGHUP)
------
Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c bun install]: exit code: 1

Pinning bun to an earlier version (v1.0.16 or earlier) does work inside of Docker:

 => [base 2/5] RUN npm install --location=global npm [email protected]                                                                                                                                                           
 => [base 3/5] WORKDIR /usr/src/app                                                                                                                                                                                       
 => [base 4/5] COPY ./package.json ./                                                                                                                                                                                     
 => [base 5/5] COPY ./bun.lockb ./                                                                                                                                                                                        
 => [dev 1/2] RUN bun install                                                                                                                                                                                             
 => [dev 2/2] COPY . .                                                                                                                                                                                                    
 => exporting to image                                                                                                                                                                                                   
 => => exporting layers

@Electroid Electroid added bun install Something that relates to the npm-compatible client docker An issue that occurs when running in Docker labels Dec 19, 2023
@mikesprague
Copy link

FWIW, this appears to be resolved for me as of bun v1.0.22

@Electroid
Copy link
Contributor

Awesome! If you still experience this issue after upgrading, leave a comment and we'll reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun install Something that relates to the npm-compatible client docker An issue that occurs when running in Docker
Projects
None yet
Development

No branches or pull requests

3 participants