kit: Seems adapter-node@1.3.0 handler.js does not load in express

Describe the bug

Upgrading from adapter-node@1.2.4 to 1.3.0, handler.js not runs in expressjs middleware.

Reproduction

Upgrade to adapter-node@1.3.0 and do npm run build

Logs

No error logs

System Info

System:
    OS: Linux 3.10 CentOS Linux 7 (Core)
    CPU: (4) x64 Intel Xeon Processor (Skylake, IBRS)
    Memory: 777.02 MB / 15.51 GB
    Container: Yes
    Shell: 4.2.46 - /bin/bash
  Binaries:
    Node: 16.20.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.6.5 - /usr/bin/npm
    pnpm: 8.6.5 - /usr/bin/pnpm
  npmPackages:
    @sveltejs/adapter-node: ^1.3.0 => 1.3.0 
    @sveltejs/kit: ^1.21.0 => 1.21.0 
    svelte: ^4.0.1 => 4.0.1 
    vite: ^4.3.9 => 4.3.9

Severity

blocking all usage of SvelteKit

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 15
  • Comments: 25 (6 by maintainers)

Commits related to this issue

Most upvoted comments

We reverted the change that caused this, 1.3.1 should not observe this issue. We’ll try to land the change again in a way that does not break. The underlying problem is a Rollup bug.

Well, I was deleted node_modules, package-lock.json, reinstall npms, delete .svelte-kit a build folders, and still the same issue. npm run preview runs ok

Rolling back to adapter-node@1.2.4 fixes the issue.

I can give you private access to our dev VM to connect your vscode through remote ssh credentials if this can help with the reproduction.

I am facing this issue too. I pinned the node adaptor to 1.2.4 for now and is working. (I have no other info to offer. there is no error, nothing shown. it just exits with 13 exit coe)

Someone on discord said it was stuck on the await server.init() line, I’m guessing the bundling probably introduces a circular import between the handler chunk and the hooks file which is dynamically imported inside server.init leading to a deadlock on the await.

Last time me and @dominikg ran into this we used manualChunks to put everything from a dependency into its own chunk. I don’t know which one(s) we’d do that for here, so probably need a better way.

I’m sorry in advance - but I am in a hurry and I can’t provide a better reproduction right now.

With this package.json, I can reproduce the error described by @NormandoHall:

{
	"name": "portal",
	"version": "0.0.1",
	"private": true,
	"scripts": {
		"dev": "vite dev",
		"build": "vite build",
		"preview": "vite preview",
		"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
		"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
		"lint": "prettier --plugin-search-dir . --check . && eslint .",
		"format": "prettier --plugin-search-dir . --write .",
		"generate-schema": "ts-node --esm ./tools/generate-schema.ts && prettier --plugin-search-dir . --write ./src/lib/schema.ts"
	},
	"devDependencies": {
		"@auth/core": "latest",
		"@auth/sveltekit": "latest",
		"@skeletonlabs/skeleton": "^1.8.0",
		"@sveltejs/adapter-node": "^1.3.0",
		"@sveltejs/kit": "^1.21.0",
		"@tailwindcss/forms": "^0.5.3",
		"@types/node": "^20.3.3",
		"@typescript-eslint/eslint-plugin": "^5.60.1",
		"@typescript-eslint/parser": "^5.60.1",
		"autoprefixer": "^10.4.14",
		"eslint": "^8.44.0",
		"eslint-config-prettier": "^8.8.0",
		"eslint-plugin-svelte": "^2.32.2",
		"json-schema-to-zod": "^0.6.3",
		"postcss": "^8.4.24",
		"prettier": "^2.8.8",
		"prettier-plugin-svelte": "^2.10.1",
		"svelte": "^4.0.1",
		"svelte-check": "^3.4.4",
		"tailwindcss": "^3.3.2",
		"ts-node": "^10.9.1",
		"tslib": "^2.6.0",
		"typescript": "^5.1.6",
		"vite": "^4.3.9",
		"zod": "^3.21.4"
	},
	"type": "module",
	"pnpm": {
		"overrides": {
			"@auth/core": "latest",
			"@auth/sveltekit": "latest"
		}
	},
	"dependencies": {
		"simple-git": "^3.19.1"
	}
}

when I instead pin adapter-node to 1.3.0 I can once again deploy our app:

{
	"name": "portal",
	"version": "0.0.1",
	"private": true,
	"scripts": {
		"dev": "vite dev",
		"build": "vite build",
		"preview": "vite preview",
		"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
		"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
		"lint": "prettier --plugin-search-dir . --check . && eslint .",
		"format": "prettier --plugin-search-dir . --write .",
		"generate-schema": "ts-node --esm ./tools/generate-schema.ts && prettier --plugin-search-dir . --write ./src/lib/schema.ts"
	},
	"devDependencies": {
		"@auth/core": "latest",
		"@auth/sveltekit": "latest",
		"@skeletonlabs/skeleton": "^1.8.0",
		"@sveltejs/adapter-node": "1.2.4",
		"@sveltejs/kit": "^1.21.0",
		"@tailwindcss/forms": "^0.5.3",
		"@types/node": "^20.3.3",
		"@typescript-eslint/eslint-plugin": "^5.60.1",
		"@typescript-eslint/parser": "^5.60.1",
		"autoprefixer": "^10.4.14",
		"eslint": "^8.44.0",
		"eslint-config-prettier": "^8.8.0",
		"eslint-plugin-svelte": "^2.32.2",
		"json-schema-to-zod": "^0.6.3",
		"postcss": "^8.4.24",
		"prettier": "^2.8.8",
		"prettier-plugin-svelte": "^2.10.1",
		"svelte": "^4.0.1",
		"svelte-check": "^3.4.4",
		"tailwindcss": "^3.3.2",
		"ts-node": "^10.9.1",
		"tslib": "^2.6.0",
		"typescript": "^5.1.6",
		"vite": "^4.3.9",
		"zod": "^3.21.4"
	},
	"type": "module",
	"pnpm": {
		"overrides": {
			"@auth/core": "latest",
			"@auth/sveltekit": "latest"
		}
	},
	"dependencies": {
		"simple-git": "^3.19.1"
	}
}

with 1.3.0 - I got zero output from my node container. none whatsoever.

this is my Dockerfile:

# use node 18
FROM node:18-bullseye

# set working directory
WORKDIR /usr/src/app

# set environment variables
ENV PNPM_HOME=/usr/local/.pnpm-store
ENV PATH=$PNPM_HOME/bin:$PATH

# install pnpm
ENV PNPM_VERSION=8.5.1
RUN npm install -g pnpm@${PNPM_VERSION}

# copy pnpm lock files
COPY pnpm-lock.yaml ./

# fetch dependencies
RUN pnpm fetch

# copy source code
COPY . ./

# install dependencies
RUN pnpm install --offline

# build app
RUN pnpm svelte-kit sync
RUN pnpm build

# set port
ENV PORT=3000
EXPOSE ${PORT}

# set user and environment
USER node
ENV NODE_ENV=production

CMD [ "node", "build" ]

maybe this is not very helpful - but at least another data point.

the issue is known - we have countless reports and reproductions in this thread. maybe we can use reactions instead of posting the same type of messages over and over again? I have notifications turned on so I get notified when there is a fix out - it’s slightly annoying to get notified for every message reporting the same issue.

thanks in advance

I am seeing the same thing. Start with a working app. Upgrade only the node adaptor v1.3.0 and the app no longer runs, giving “Command failed with exit code 13”

This isn’t using Express, it’s using the node “http” package to host the handler. But trying to launch the app using node build just exits back to the terminal with no message at all.

Reproduction repository: https://github.com/ollema/node-adapter-repro

Reproduction steps:

  1. Clone the repo, cd node-adapter-repro and pnpm install
  2. Run docker build -t node-adapter-repro . && docker run --rm -it node-adapter-repro
  3. Notice how the container exits without printing anything
  4. Rollback to 1.2.4: pnpm add -D @sveltejs/adapter-node@1.2.4
  5. Run docker build -t node-adapter-repro . && docker run --rm -it node-adapter-repro again
  6. Notice how it now works and prints: Listening on 0.0.0.0:3000

Can you confirm @NormandoHall?


In the README.md for this repo I have also included every step needed to recreate a project with this issue from the initial pnpm create svelte@latest step (I think).

@ollema yes, there is no output:

docker build -t node-adapter-repro . && docker run --rm -it node-adapter-repro
[+] Building 367.1s (14/14) FINISHED
 => [internal] load .dockerignore                                                                                                                                                                                                       0.2s
 => => transferring context: 2B                                                                                                                                                                                                         0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                                    0.3s
 => => transferring dockerfile: 711B                                                                                                                                                                                                    0.1s
 => [internal] load metadata for docker.io/library/node:18-bullseye                                                                                                                                                                     2.5s
 => [1/9] FROM docker.io/library/node:18-bullseye@sha256:68682a082afb25f72c4941f2d6f5c063344af02901ee555902869a67461dc391                                                                                                             315.4s
 => => resolve docker.io/library/node:18-bullseye@sha256:68682a082afb25f72c4941f2d6f5c063344af02901ee555902869a67461dc391                                                                                                               0.0s
 => => sha256:de52b24628074d91c1b6455a6b891cdfd3ec71ec8916dda61a73356f4a36f43f 2.00kB / 2.00kB                                                                                                                                          0.0s
 => => sha256:93c2d578e4211e82e47e7ada9ed05d1869a2362c6f7509f2ee8d91ccebfb7fbd 55.06MB / 55.06MB                                                                                                                                      122.2s
 => => sha256:c87e6f3487e1d7e61ee7a415e0ced4eb6f0b3484eb1e15a4339d110d3cadf899 15.76MB / 15.76MB                                                                                                                                       24.8s
 => => sha256:65b4d59f9abaeb4efe1c66ff2176044e93912966342d76d025b6d1a2a37dde7a 54.59MB / 54.59MB                                                                                                                                      137.3s
 => => sha256:68682a082afb25f72c4941f2d6f5c063344af02901ee555902869a67461dc391 1.21kB / 1.21kB                                                                                                                                          0.0s
 => => sha256:c40e0caabcca77b360307e9515d00d9308001f93c12a37c5cc641b17f222b6c6 7.24kB / 7.24kB                                                                                                                                          0.0s
 => => sha256:d7edca23d42bd7903919d8184b978cfe282dbac5a142296e26b4dd53367425f4 196.85MB / 196.85MB                                                                                                                                    303.7s
 => => sha256:25c206b29ffe0e98ff5e9c6359450d67d3691017999f2cc1175c48b941f7c053 4.20kB / 4.20kB                                                                                                                                        122.7s
 => => extracting sha256:93c2d578e4211e82e47e7ada9ed05d1869a2362c6f7509f2ee8d91ccebfb7fbd                                                                                                                                               2.4s
 => => sha256:bdf1a95618f675b55822c42e7c4d84070d68e251e2759e0fa3b07ed6749bcd3d 45.53MB / 45.53MB                                                                                                                                      227.3s
 => => extracting sha256:c87e6f3487e1d7e61ee7a415e0ced4eb6f0b3484eb1e15a4339d110d3cadf899                                                                                                                                               0.5s
 => => sha256:b4675c226ed38d0c140fe99ae1f5c56ae86470cb817ee6d57b4614fe6f19fe42 2.28MB / 2.28MB                                                                                                                                        141.6s
 => => extracting sha256:65b4d59f9abaeb4efe1c66ff2176044e93912966342d76d025b6d1a2a37dde7a                                                                                                                                               2.7s
 => => sha256:dfbe26d2f5fc2fb463c361af023945b654a303ca568d94853e3ac473680bfcee 449B / 449B                                                                                                                                            141.8s
 => => extracting sha256:d7edca23d42bd7903919d8184b978cfe282dbac5a142296e26b4dd53367425f4                                                                                                                                               8.2s
 => => extracting sha256:25c206b29ffe0e98ff5e9c6359450d67d3691017999f2cc1175c48b941f7c053                                                                                                                                               0.1s
 => => extracting sha256:bdf1a95618f675b55822c42e7c4d84070d68e251e2759e0fa3b07ed6749bcd3d                                                                                                                                               2.4s
 => => extracting sha256:b4675c226ed38d0c140fe99ae1f5c56ae86470cb817ee6d57b4614fe6f19fe42                                                                                                                                               0.2s
 => => extracting sha256:dfbe26d2f5fc2fb463c361af023945b654a303ca568d94853e3ac473680bfcee                                                                                                                                               0.0s
 => [internal] load build context                                                                                                                                                                                                       1.7s
 => => transferring context: 101.68MB                                                                                                                                                                                                   1.7s
 => [2/9] WORKDIR /usr/src/app                                                                                                                                                                                                          1.5s
 => [3/9] RUN npm install -g pnpm@8.5.1                                                                                                                                                                                                 5.6s
 => [4/9] COPY pnpm-lock.yaml ./                                                                                                                                                                                                        0.1s
 => [5/9] RUN pnpm fetch                                                                                                                                                                                                               21.0s
 => [6/9] COPY . ./                                                                                                                                                                                                                     1.5s
 => [7/9] RUN pnpm install --offline                                                                                                                                                                                                    2.7s
 => [8/9] RUN pnpm svelte-kit sync                                                                                                                                                                                                      2.8s
 => [9/9] RUN pnpm build                                                                                                                                                                                                               10.6s
 => exporting to image                                                                                                                                                                                                                  2.5s
 => => exporting layers                                                                                                                                                                                                                 2.5s
 => => writing image sha256:7f0f71bc2bb17883f071b8f4eb069ae33080cc237b3a304c38acdeb5cafaa9bc                                                                                                                                            0.0s
 => => naming to docker.io/library/node-adapter-repro                                                                                                                                                                                   0.0s
WARNING: buildx: failed to read current commit information with git rev-parse --is-inside-work-tree
[root@vm-desarrollo node-adapter-repro]#

UPDATE: Rolling back to 1.2.4:

[+] Building 39.1s (14/14) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                                    0.0s
 => => transferring dockerfile: 711B                                                                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                       0.0s
 => => transferring context: 2B                                                                                                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/node:18-bullseye                                                                                                                                                                     0.5s
 => [1/9] FROM docker.io/library/node:18-bullseye@sha256:68682a082afb25f72c4941f2d6f5c063344af02901ee555902869a67461dc391                                                                                                               0.0s
 => [internal] load build context                                                                                                                                                                                                       1.6s
 => => transferring context: 101.48MB                                                                                                                                                                                                   1.6s
 => CACHED [2/9] WORKDIR /usr/src/app                                                                                                                                                                                                   0.0s
 => CACHED [3/9] RUN npm install -g pnpm@8.5.1                                                                                                                                                                                          0.0s
 => [4/9] COPY pnpm-lock.yaml ./                                                                                                                                                                                                        1.0s
 => [5/9] RUN pnpm fetch                                                                                                                                                                                                               19.8s
 => [6/9] COPY . ./                                                                                                                                                                                                                     1.8s
 => [7/9] RUN pnpm install --offline                                                                                                                                                                                                    1.1s
 => [8/9] RUN pnpm svelte-kit sync                                                                                                                                                                                                      2.5s
 => [9/9] RUN pnpm build                                                                                                                                                                                                                7.7s
 => exporting to image                                                                                                                                                                                                                  2.9s
 => => exporting layers                                                                                                                                                                                                                 2.9s
 => => writing image sha256:6284c7e91cd8a11f53722a9c0486269e8d9dd790503ddefdc85135f72a98126f                                                                                                                                            0.0s
 => => naming to docker.io/library/node-adapter-repro                                                                                                                                                                                   0.0s
Listening on 0.0.0.0:3000

Okay, so there is something strange going on for sure. Without changing package.json, I managed to get it working by removing routes/hooks/other things from my reproduction repo.

I will try to “bisect” to pin down what is needed to make it not work again

edit:

started working when I removed my hooks.server.ts:

import { sequence } from '@sveltejs/kit/hooks';

import { authentication } from '$lib/server/authentication';
import { authorization } from '$lib/server/authorization';

export const handle = sequence(authentication, authorization);

will continue to remove unrelated stuff and try to post a reproduction repo

import { handler } from './build/handler.js';
import express from 'express';
const app = express();

console.log(1);

// add a route that lives separately from the SvelteKit app
app.get('/healthcheck', (req, res) => {
  res.end('ok');
});

// let SvelteKit handle everything else, including serving prerendered pages and static assets
app.use(handler);

app.listen(13030, '127.0.0.1', () => {
  console.log('listening on port 13030');
});

With the above code, there is no 1 console output nor listening on port 13030

Commenting import { handler } from './build/handler.js'; and app.use(handler); express runs and get the console output 1 and listening on port 13030