kit icon indicating copy to clipboard operation
kit copied to clipboard

Docker build with node Adapter failed with : Could not resolve entry module (index.html).

Open xmlking opened this issue 2 years ago • 4 comments

Describe the bug

Docker build with nodeAdapter '@sveltejs/adapter-node'; npm run build

npm run build works fine on the local machine without docker.

import adapter from '@sveltejs/adapter-auto';
import staticAdapter from '@sveltejs/adapter-static';
import nodeAdapter from '@sveltejs/adapter-node';
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://github.com/sveltejs/svelte-preprocess
	// for more information about preprocessors
	preprocess: [
		preprocess({
			postcss: true
		})
	],

	kit: {
		adapter: getAdapter(),

		// Override http methods in the Todo forms
		methodOverride: {
			allowed: ['PUT', 'PATCH', 'DELETE']
		}
	}
};

export default config;

function getAdapter() {
	switch (process.env.ADAPTER) {
		case 'node':
			return nodeAdapter({
				out: 'build/dist',
				precompress: false
				// default: HOST=0.0.0.0 PORT=3000
				/*
				env: {
					host: 'HOST',
					port: 'PORT'
				}
				*/
			});
		case 'static':
			return staticAdapter({
				pages: 'build/dist',
				assets: 'build/dist',
				fallback: 'index.html', // 404.html,
				// trailingSlash: 'always'
			});
		default:
			return adapter();
	}
}

Reproduction

# syntax=docker/dockerfile:1.4

# Add tini to act as PID1 for proper signal handling
FROM --platform=${BUILDPLATFORM} alpine as tini
ENV TINI_VERSION v0.19.0
# Use BuildKit to help translate architecture names
ARG TARGETPLATFORM
# translating Docker's TARGETPLATFORM into tini download names
RUN case ${TARGETPLATFORM} in \
		"linux/amd64")  TINI_ARCH=amd64  ;; \
		"linux/arm64")  TINI_ARCH=arm64  ;; \
		"linux/arm/v7") TINI_ARCH=armhf  ;; \
		"linux/arm/v6") TINI_ARCH=armel  ;; \
		"linux/386")    TINI_ARCH=i386   ;; \
    esac \
    && wget -q https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static-${TINI_ARCH} -O /tini \
    && chmod +x /tini

# This stage builds the application.
FROM --platform=${BUILDPLATFORM} node:18 as build-app
WORKDIR /app

COPY . .
# clean install all dependencies
RUN npm ci --no-audit --unsafe-perm
# remove potential security issues
RUN npm audit fix
# build SvelteKit app
RUN npm run build:node

# This stage installs the runtime dependencies.
FROM --platform=${BUILDPLATFORM} node:18-alpine as build-runtime
WORKDIR /app
COPY package.json package-lock.json ./
# clean install dependencies, no devDependencies, no prepare script
#RUN --mount=type=cache,target=/root/.cache/node \
#    --mount=type=cache,target=/root/.cache/node-build \
#    npm ci --production --unsafe-perm --ignore-scripts

RUN npm ci --production --unsafe-perm --ignore-scripts
# remove potential security issues
RUN npm audit fix

# This stage only needs the compiled application and the runtime dependencies.
FROM gcr.io/distroless/nodejs:18 as final
#FROM gcr.io/distroless/nodejs:18-debug as final
ENV NODE_ENV production

WORKDIR /app
COPY --from=tini /tini /tini
ENTRYPOINT ["/tini", "--", "/nodejs/bin/node"]
COPY --from=build-app /app/build/dist ./build
COPY --from=build-app /app/config ./config
COPY --from=build-app /app/proto ./proto
COPY --from=build-runtime /app/package.json ./package.json
COPY --from=build-runtime /app/node_modules ./node_modules

EXPOSE 3000
#USER nonroot:nonroot


CMD ["build"]

Logs

=> [linux/arm64 build-app 5/6] RUN npm audit fix                                                                                                                                                                                                                                                                  1.1s
 => ERROR [linux/arm64 build-app 6/6] RUN npm run build:node                                                                                                                                                                                                                                                       0.6s
------
 > [linux/arm64 build-app 6/6] RUN npm run build:node:
#0 0.243 
#0 0.243 > [email protected] build:node
#0 0.243 > cross-env ADAPTER=node npm run build
#0 0.243 
#0 0.433 
#0 0.433 > [email protected] build
#0 0.433 > vite build
#0 0.433 
#0 0.551 vite v3.1.0 building for production...
#0 0.575 ✓ 0 modules transformed.
#0 0.575 Could not resolve entry module (index.html).
#0 0.577 error during build:
#0 0.577 Error: Could not resolve entry module (index.html).
#0 0.577     at error (file:///app/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
#0 0.577     at ModuleLoader.loadEntryModule (file:///app/node_modules/rollup/dist/es/shared/rollup.js:22369:20)
#0 0.577     at async Promise.all (index 0)

System Info

System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 25.44 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.7.0 - /opt/homebrew/bin/node
    npm: 8.15.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
    Safari: 16.1

Severity

blocking an upgrade

Additional Information

image

xmlking avatar Sep 05 '22 17:09 xmlking

A dockerfile is not a repro. Please follow the instructions you saw when you opened this issue https://github.com/sveltejs/kit/blob/master/.github/ISSUE_TEMPLATE/bug_report.yml

Rich-Harris avatar Sep 06 '22 13:09 Rich-Harris

A dockerfile is not a repro. Please follow the instructions you saw when you opened this issue https://github.com/sveltejs/kit/blob/master/.github/ISSUE_TEMPLATE/bug_report.yml @Rich-Harris I will make a public repo and share it shortly.

PS: same docker build was working before I updated sveltekit to the latest version.

xmlking avatar Sep 07 '22 04:09 xmlking

Here is the minimal repo to reproduce docker build error https://github.com/xmlking/svelte-starter-kit This repo is created with npm create svelte@latest my-app

clone this repo and try to build docker image following doc https://github.com/xmlking/svelte-starter-kit/blob/main/docs/docker.md

xmlking avatar Sep 09 '22 23:09 xmlking

my bad. I missed including the newly added /vite.config.ts file in my .dockerignore

after including /vite.config.ts, it worked as expected.

But the error message was weird. Could not resolve entry module (index.html). 🤯

.dockerignore

/*
!/package.json
!/package-lock.json
!/svelte.config.js
!/tailwind.config.cjs
!/vite.config.js
!/postcss.config.cjs
!/src
!/static
!/config
!/tsconfig.json
!/vite.config.ts

xmlking avatar Sep 10 '22 04:09 xmlking

Sounds like the issue was resolved, closing.

dummdidumm avatar Jan 11 '23 09:01 dummdidumm