Skip to content

Typescript in script with context="module" Sapper server side rendering #156

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

Closed
dionysiusmarquis opened this issue May 26, 2020 · 2 comments

Comments

@dionysiusmarquis
Copy link

dionysiusmarquis commented May 26, 2020

Describe the bug

If you the <script context="module"> docs in Sapper environment and add lang="typescript" to both <script> elements the page/component will not be rendererd server side. Instead of the page/component render the server will response an 500 error.

To Reproduce

Here is a repo to reproduce. It is a fork of sapper-template-rollup. With only the preprocessor and some simple typescript declarations and lang="typescript" added (see diff). If you go to http://localhost:3000/blog you will get an 500 error. If you go to the blog via navigation link it will render correctly.

https://github.com/dionysiusmarquis/sapper-template-rollup/tree/bug/typescript-context-module

Expected behavior

Preprocessor to be able to handle typescript in Svelte module context for preload functionality.

Stacktraces

Inside the page/component as server response

500
Cannot read property 'length' of undefined

TypeError: Cannot read property 'length' of undefined
    at each (/…/__sapper__/dev/server/server.js:200:31)
    at create_ssr_component (/…/__sapper__/dev/server/server.js:305:35)
    at Object.$$render (/…/__sapper__/dev/server/server.js:230:22)
    at Object.default (/…/__sapper__/dev/server/server.js:548:86)
    at create_ssr_component (/…/__sapper__/dev/server/server.js:375:70)
    at Object.$$render (/…/__sapper__/dev/server/server.js:230:22)
    at create_ssr_component (/…/__sapper__/dev/server/server.js:545:40)
    at $$render (/…/__sapper__/dev/server/server.js:230:22)
    at Object.render (/…/__sapper__/dev/server/server.js:238:26)
    at handle_page (/…/__sapper__/dev/server/server.js:3021:36)

Information about your project:

  • Your browser and the version: Chromium Version 80.0.3987.122 (Official Build) (64-bit)
  • Your operating system: OS X 10.13.6
  • svelte version 3.22.3
  • sapper version 0.27.13
  • svelte-preprocess version 3.7.4
  • Rollup
@dionysiusmarquis
Copy link
Author

dionysiusmarquis commented May 26, 2020

I just realized that the Rollup warnings are always pressend as soon as you add a function which returns a Promise. Even without context="module". Could this be related anyhow 🤔. Otherwise the warnings might be another "issue"

Edit: I edited the issue and removed the Rollup part. I changed the tsconfig.json to:

{
    "compilerOptions": {
        "target": "ESNext",
        "module": "ESNext" 
    },
    "include": ["src/**/*"],
    "exclude": ["node_modules", "**/*.spec.ts"]
}

This will prevent typescript recompiling async functions

@dionysiusmarquis
Copy link
Author

This is a sapper issue see: sveltejs/sapper#1241

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

No branches or pull requests

1 participant