Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Module context preload function not present in server.js bundle #1241

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

Comments

@dionysiusmarquis
Copy link

Describe the bug

As soon as you add an preload function to an <script context="module" lang="typescript"> the preload function won't be present in the bundled server.js.
First I thought it is a bug in svelte-preprocess. But I was able to break it down to sapper by creating a simple preprocessor. The preprocessor creates valid js but the preload function will not be present if it was invalid js before the processor.

See original issue: sveltejs/svelte-preprocess#156

To Reproduce
create a simple preprocessor:

preprocess: {
  script: ({ content, attributes, filename }) => {
    return { code: content.replace(': any[]', '') };
  }
}

create a route or component with a preload function:

<script context="module">
  export function preload({ params, query }) {
    const posts: any[] = []
    return { posts }
}
</script>

<script>
  export let posts
</script>

Expected behavior

The reload function in module context should be present in the bundled server.js

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
  • Rollup

Severity

I will only be able to use sapper as soon as I'm able to use Typescript. So this is actually blocking me from using sapper.

@benmccann
Copy link
Member

I'm wondering if this is because you need #1222. Give my fork a try and let me know if it works for you: #760 (comment)

@Conduitry
Copy link
Member

Yeah this is gonna be the same issue of Sapper not being able to detect the preload function if Svelte can't compile the component as-is.

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

No branches or pull requests

3 participants