Closed letmejustputthishere closed 3 years ago
Hey dude,
What worked for me is to rather use express - what seemed to be the problem was the type declarations that the polka library is using. So:
npm install express
npm install --save-dev @types/express
then change your server.js file to look something like this:
import sirv from "sirv";
import polka from "polka";
import compression from "compression";
import * as sapper from "@sapper/server";
import express from "express";
const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === "development";
express()
.use(
compression({ threshold: 0 }),
sirv("static", { dev }),
sapper.middleware()
)
.listen(PORT, () => {
});
and then to fix the interop problem I was getting, add "esModuleInterop": true to your tsconfig file:
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"lib": [
"DOM",
"ES2017",
"WebWorker"
]
},
"include": [
"src/**/*",
"src/node_modules/**/*"
],
"exclude": [
"node_modules/*",
"__sapper__/*",
"static/*"
],
"esModuleInterop": true
}
Hope this helps!
Can confirm https://github.com/sveltejs/sapper/issues/1783#issuecomment-869221926 resolves the error. Though I have no idea what the implications of this change are.
There aren't implications - Express and Polka are interchangeable in this regard.
The issue was being caused with the typing of Polka middleware, which is what the compression() function is. It is typed as a RequestHandler and not whatever Polka types their middleware as. So a quick workaround is just to swop out polka with express, which is what we did :)
Thank you very much @ilikepi63 , that did the trick :)
I'm still experiencing this. Steps to reproduce:
Leads to:
Originally posted by @letmejustputthishere in https://github.com/sveltejs/sapper/issues/1706#issuecomment-863952613
After updating to v0.29.1, the issue still persists.