question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vite + Esbuild Docker issue

See original GitHub issue

Describe the bug

I’m trying to Docker build my app, and although the build phase is working fine on my laptop, I’m getting this when building the Docker image:

 > [build-stage 6/6] RUN npm run build:
#10 0.436 
#10 0.436 > tailwind-dashboard@0.0.1 build /app
#10 0.436 > cross-env NODE_ENV=production vite build --debug
#10 0.436 
#10 0.766 [vite] failed to load config from /app/vite.config.js:
#10 0.771 Error: spawn Unknown system error -8
#10 0.771     at ChildProcess.spawn (internal/child_process.js:403:11)
#10 0.771     at Object.spawn (child_process.js:553:9)
#10 0.771     at Object.startService (/app/node_modules/esbuild/lib/main.js:1066:29)
#10 0.771     at ensureService (/app/node_modules/vite/dist/node/esbuildService.js:39:37)
#10 0.771     at Object.transform (/app/node_modules/vite/dist/node/esbuildService.js:53:27)
#10 0.771     at Object.renderChunk (/app/node_modules/vite/dist/node/build/buildPluginEsbuild.js:39:37)
#10 0.771     at /app/node_modules/rollup/dist/shared/rollup.js:18804:25 {
#10 0.771   errno: -8,
#10 0.771   code: 'PLUGIN_ERROR',
#10 0.771   syscall: 'spawn',
#10 0.771   pluginCode: 'Unknown system error -8',
#10 0.771   plugin: 'vite:esbuild-transpile',
#10 0.771   hook: 'renderChunk'
#10 0.771 }

My Dockerfile is the same as in the Vue documentation:

# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Reproduction

Use the Dockerfile above to run the app located at https://github.com/ocervell/v-dashboard/tree/slo-ui-v1.

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 9.70 GB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 15.10.0 - ~/homebrew/bin/node
    Yarn: 1.22.10 - ~/Workspace/dev/poc/slo-generator-poc/slo-generator-ui/node_modules/.bin/yarn
    npm: 7.5.3 - ~/homebrew/bin/npm
  Browsers:
    Chrome: 89.0.4389.90
    Safari: 14.0.3
  npmPackages:
    vite: ^1.0.0-rc.8 => 1.0.0-rc.13

Logs


[build-stage 6/6] RUN npm run build: #12 0.455 #12 0.455 > tailwind-dashboard@0.0.1 build /app #12 0.455 > cross-env NODE_ENV=production vite build --debug #12 0.455 #12 0.803 [vite] failed to load config from /app/vite.config.js: #12 0.820 Error: spawn Unknown system error -8 #12 0.820 at ChildProcess.spawn (internal/child_process.js:403:11) #12 0.820 at Object.spawn (child_process.js:553:9) #12 0.820 at Object.startService (/app/node_modules/esbuild/lib/main.js:1066:29) #12 0.820 at ensureService (/app/node_modules/vite/src/node/esbuildService.ts:52:23) #12 0.820 at Object.transform (/app/node_modules/vite/src/node/esbuildService.ts:72:25) #12 0.820 at Object.renderChunk (/app/node_modules/vite/src/node/build/buildPluginEsbuild.ts:56:14) #12 0.820 at /app/node_modules/rollup/dist/shared/rollup.js:18804:25 { #12 0.820 errno: -8, #12 0.820 code: ‘PLUGIN_ERROR’, #12 0.820 syscall: ‘spawn’, #12 0.820 pluginCode: ‘Unknown system error -8’, #12 0.820 plugin: ‘vite:esbuild-transpile’, #12 0.820 hook: ‘renderChunk’ #12 0.820 } #12 0.836 npm ERR! code ELIFECYCLE #12 0.837 npm ERR! errno 1 #12 0.841 npm ERR! tailwind-dashboard@0.0.1 build: cross-env NODE_ENV=production vite build --debug #12 0.841 npm ERR! Exit status 1 #12 0.841 npm ERR! #12 0.842 npm ERR! Failed at the tailwind-dashboard@0.0.1 build script. #12 0.842 npm ERR! This is probably not a problem with npm. There is likely additional logging output above. #12 0.847 #12 0.847 npm ERR! A complete log of this run can be found in: #12 0.847 npm ERR! /root/.npm/_logs/2021-03-24T10_58_32_077Z-debug.log


failed to solve with frontend dockerfile.v0: failed to build LLB: executor failed running [/bin/sh -c npm run build]: runc did not terminate sucessfully.


Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
raf4q0commented, Apr 13, 2021

@callmeberzerker It was silly mistake on my side. I needed to mount my node_modules separately it has nothing to do with esbuild it was just only os specific dependency being built.

services:
  client:
    ...
    volumes:
      - ./client:/base
      - client_node_modules:/base/node_modules/

volumes:
  client_node_modules:

or

services:
  client:
    ...
    volumes:
      - ./client:/base
      - /base/node_modules/

1reaction
nihalgonsalvescommented, Apr 29, 2021

Copying this over here in case anyone’s looking for another workaround. Add an ENTRYPOINT, and the correct architecture will be built inside the container on startup. This way you don’t need to exclude your node_modules using an empty volume either.

  • entrypoint.sh

    #!/bin/sh
    
    npm rebuild esbuild
    
    exec "$@"
    
  • Dockerfile

    # ...
    
    COPY entrypoint.sh /entrypoint.sh
    RUN chmod +x /entrypoint.sh
    
    ENTRYPOINT ["/entrypoint.sh"]
    
    # ...
    

(Alternatively, simply run npm rebuild esbuild with docker exec or docker compose exec)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vite React app: esbuild error in Docker container
I'm running into an issue with esbuild inside docker. I'm trying to get a dev setup going, so I want to mount my...
Read more >
Step By Step Guide To Dockerize React App Created Using Vite
In this post, you'll learn how to dockerize your react app created using the Vite tool for the development environment Docker is a...
Read more >
Vite React app: esbuild error in Docker container-Reactjs
So, I need to rebuild esbuild inside the container. I tried to use the entrypoint script as that thread suggests but that didn't...
Read more >
Troubleshooting | Vite Ruby
esbuild : cannot execute binary file #. This can happen when using mounted volumes in Docker, and attempting to run Vite from the...
Read more >
4 Reasons Why You Should Prefer Vite Over Create-React ...
Unlike CRA, Vite does not build your entire application before serving, ... It also leverages the power of native ES modules, esbuild, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found