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

[vite] error while transforming /app/client/vite.config.ts with esbuild in Docker image #876

Closed
brmdbr opened this issue Oct 3, 2020 · 10 comments

Comments

@brmdbr
Copy link

brmdbr commented Oct 3, 2020

Describe the bug

Following error when trying to run vite build in a docker container. I tried to convert the config file to a JS file but then it throws an error on my main.ts. On my (windows) development pc the build command works perfectly.

> vite build --debug

vite v1.0.0-rc.4
[vite] error while transforming /app/client/vite.config.ts with esbuild:
Error: The service was stopped
    at /app/client/node_modules/esbuild/lib/main.js:405:31
    at Socket.afterClose (/app/client/node_modules/esbuild/lib/main.js:331:7)
    at Socket.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1252:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
2020-10-03T10:43:26.410Z vite:esbuild options used:  {
  loader: 'ts',
  sourcemap: true,
  sourcefile: '/app/client/vite.config.ts',
  target: 'es2020',
  jsxFactory: undefined,
  jsxFragment: undefined
}
2020-10-03T10:43:26.422Z vite:config env mode: production
2020-10-03T10:43:26.424Z vite:config env: { VITE_API_URL: 'http://localhost:3000' }
2020-10-03T10:43:26.424Z vite:config config resolved in 116ms
Building for production...
[vite] Build errored out.
Error: Could not resolve entry module (index.html).
    at error (/app/client/node_modules/rollup/dist/shared/rollup.js:5210:30)
    at ModuleLoader.loadEntryModule (/app/client/node_modules/rollup/dist/shared/rollup.js:18295:16)
    at async Promise.all (index 0) {
  code: 'UNRESOLVED_ENTRY'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bitcoin-warzone-client@0.0.1 build: `vite build --debug`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bitcoin-warzone-client@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Vite: 1.0.0-rc.4
Docker image: https://hub.docker.com/_/node (tried multiple)

Dockerfile:

#BUILD
FROM node:14-alpine AS builder

WORKDIR /app

COPY ./server/package*.json ./server/
COPY ./client/package*.json ./client/

RUN cd server && npm install
RUN cd client && npm install

COPY . .

RUN cd server && npm run build
RUN cd client && npm run build

#SERVE
FROM node:14-alpine

WORKDIR /app

COPY --from=builder /app ./

EXPOSE 3000

WORKDIR /app/server

CMD ["npm", "run", "start:prod"]

Reproduction/System Info

I have tried tens of different docker containers with node installed, they all give me this error.

Logs (Optional if provided reproduction)

I ran with the --debug flag.

@ais-one
Copy link
Contributor

ais-one commented Oct 3, 2020

Maybe you can try this...

  1. your docker could be missing some dependencies, use ubuntu instead of alpine image...

  2. build your frontend first on the host rather than in the container...

@underfin
Copy link
Member

underfin commented Oct 4, 2020

You should add index.html into your container.

@underfin underfin closed this as completed Oct 4, 2020
@brmdbr
Copy link
Author

brmdbr commented Oct 4, 2020

@underfin its there, I copy all of it to the container, hence COPY . ..

This is my project structure:

image

@brmdbr
Copy link
Author

brmdbr commented Oct 4, 2020

Maybe you can try this...

  1. your docker could be missing some dependencies, use ubuntu instead of alpine image...
  2. build your frontend first on the host rather than in the container...

Thanks for the suggestions.

  1. I tried a bunch, maybe I need to try some more.
  2. I'd like to publish the docker image from a github action, don't think building outside the container will work then. Or am I wrong here?

@brmdbr
Copy link
Author

brmdbr commented Oct 4, 2020

@underfin Also: running the same on my develop pc does work.

Why close this issue?

@brmdbr
Copy link
Author

brmdbr commented Oct 4, 2020

Seems related to: shortpoet/vite-ts-docker#1 but propose solution doesn't work. @gioxoay @shortpoet

@brmdbr
Copy link
Author

brmdbr commented Oct 4, 2020

Changed the location of the index.html.
Error now:

`vite v1.0.0-rc.4
[vite] error while transforming /app/client/vite.config.ts with esbuild:
Error: The service was stopped
at /app/client/node_modules/esbuild/lib/main.js:405:31
at Socket.afterClose (/app/client/node_modules/esbuild/lib/main.js:331:7)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1252:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)

  • Building for production...

[vite] error while transforming /app/client/src/main.ts with esbuild:
Error: The service is no longer running
at /app/client/node_modules/esbuild/lib/main.js:405:31
at sendRequest (/app/client/node_modules/esbuild/lib/main.js:337:14)
at start (/app/client/node_modules/esbuild/lib/main.js:399:11)
at Object.transform (/app/client/node_modules/esbuild/lib/main.js:441:9)
at /app/client/node_modules/esbuild/lib/main.js:557:78
at new Promise ()
at Object.transform (/app/client/node_modules/esbuild/lib/main.js:557:37)
at Object.exports.transform (/app/client/node_modules/vite/dist/node/esbuildService.js:60:38)
Generated an empty chunk: "index"

  • Building for production...

[vite] error while transforming index.553e494c.js with esbuild:
Error: The service is no longer running
at /app/client/node_modules/esbuild/lib/main.js:405:31
at sendRequest (/app/client/node_modules/esbuild/lib/main.js:337:14)
at start (/app/client/node_modules/esbuild/lib/main.js:399:11)
at Object.transform (/app/client/node_modules/esbuild/lib/main.js:441:9)
at /app/client/node_modules/esbuild/lib/main.js:557:78
at new Promise ()
at Object.transform (/app/client/node_modules/esbuild/lib/main.js:557:37)
at Object.exports.transform (/app/client/node_modules/vite/dist/node/esbuildService.js:60:38)
[write] dist/_assets/index.553e494c.js 0.00kb, brotli: 0.00kb
[write] dist/index.html 0.74kb, brotli: 0.26kb
Build completed in 0.72s.`

@brmdbr
Copy link
Author

brmdbr commented Oct 5, 2020

Using the 14-buster-slim image to build fixed it for me

@nazmifeeroz
Copy link

I managed to get this work by running

RUN node node_modules/esbuild/install.js

before the build command.

@tklinh
Copy link

tklinh commented Apr 28, 2021

I managed to get this work by running

RUN node node_modules/esbuild/install.js

before the build command.

Thank you very much. It works for me too.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants