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

@sveltejs/adapter-node error when used as handler with native node http package #8888

Closed
CaptainCodeman opened this issue Feb 5, 2023 · 3 comments · Fixed by #8890
Closed

Comments

@CaptainCodeman
Copy link
Contributor

CaptainCodeman commented Feb 5, 2023

Describe the bug

Using @sveltejs/adapter-node v1.1.6 fails with a cryptic error message when trying to use the handler with the inbuilt node http package, but works with express.

Reproduction

This fails:

import http from 'http'
import { handler } from './build/handler.js'

http.createServer(handler).listen(3000)

This works:

import express from 'express'
import { handler } from './build/handler.js'

express().use(handler).listen(3000)

Logs

Error: Not found: /
    at resolve (file:///project/build/server/index.js:3178:18)
    at resolve (file:///project/build/server/index.js:3045:34)
    at #options.hooks.handle (file:///project/build/server/index.js:3223:59)
    at respond (file:///project/build/server/index.js:3043:43)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Array.ssr (file:///project/build/handler.js:21839:3)

System Info

System:
    OS: macOS 13.2
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 2.70 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.10.0 - ~/Library/pnpm/node
    npm: 8.19.2 - ~/Library/pnpm/npm
  Browsers:
    Brave Browser: 106.1.44.112
    Chrome: 109.0.5414.119
    Chrome Canary: 112.0.5579.0
    Firefox: 109.0
    Safari: 16.3
    Safari Technology Preview: 16.4
  npmPackages:
    @sveltejs/adapter-node: 1.1.5 => 1.1.6 
    @sveltejs/kit: ^1.3.10 => 1.3.10 
    svelte: ^3.55.1 => 3.55.1 
    vite: ^4.1.1 => 4.1.1

Severity

serious, but I can work around it

Additional Information

Rolling back to @sveltejs/adapter-node v1.1.5 works.

I don't want to add express as an extra dependency and the real server script includes other things (static file caching, proxy and http compression)

@maietta
Copy link

maietta commented Feb 5, 2023

Is this possibly related to what I am suddenly encountering with failed fetches using the fetch API?

Seems like something broke just recently.

@gtm-nayan
Copy link
Contributor

gtm-nayan commented Feb 5, 2023

Problem lies in this line

The path property isn't available on the IncomingMessage object for the native server but there is a pseudo-private _parsedUrl.pathname property. Although, I think the two properties have different semantics when used within express/polka middlewares mounted with different base paths.

Edit: the _parsedUrl property is added by sirv and not a node thing so the question is whether to rely on @polka/url and reuse the already parsed URL or use parse from node:url (which is going through Schrodinger's deprecation).

@maietta
Copy link

maietta commented Feb 5, 2023

I think your problem is different from mine. Your problem seems more specific. Hope you find the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants