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

Exported members from context=module cannot be imported into Typescript files #658

Closed
curiousdannii opened this issue Oct 10, 2024 · 4 comments

Comments

@curiousdannii
Copy link

I've run into this issue: sveltejs/svelte#5817. On the main svelte repo the response was basically "not out problem". So I'm refiling it here, as I think this is the component that would have actual responsibility for this issue.

Describe the bug
I have a Svelte component which exports some constants in its context="module":

<script context="module" lang="ts">
    export const ALERT_MODE_ALERT = 0
    export const ALERT_MODE_CONFIRM = 1
    export const ALERT_MODE_PROMPT = 2
</script>

I want to import a constant into a regular typescript file:

import AlertDialog, {ALERT_MODE_ALERT} from './ui/AlertDialog.svelte'

When building purely with tsc, no bundler or anything (just with "types": ["svelte"], in tsconfig.json) I get this error:

src/dialog/browser/browser.ts:19:22 - error TS2614: Module '"*.svelte"' has no exported member 'ALERT_MODE_ALERT'. Did you mean to use 'import ALERT_MODE_ALERT from "*.svelte"' instead?

19 import AlertDialog, {ALERT_MODE_ALERT} from './ui/AlertDialog.svelte'

Expected behavior
The constant can be imported into another TS file.

  • svelte-preprocess version (Please check you can reproduce the issue with the latest release!)

6.0.3

  • Whether your project uses Webpack or Rollup

Nope!

@dummdidumm
Copy link
Member

As outlined in the referenced issue, this is a type checking problem, and in your editor your can solve it by having the TypeScript plugin installed (comes by default with VS Code), and in your terminal/CI you should use svelte-check instead of tsc, because the latter is not aware of Svelte-specifics. There's nothing svelte-preprocess can do here, therefore closing.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2024
@curiousdannii
Copy link
Author

curiousdannii commented Oct 10, 2024

This is not about VS Code or any other editor. This error occurs when I'm type checking/compiling my app's typescript code. I had thought svelte-check only checked .svelte files, if it also checks .ts files (as tsc would), great. But that still doesn't help with the actual output of my code. Unless you mean that Svelte users have to run tsc --noCheck if the want to use the exports of context=module?

@dummdidumm
Copy link
Member

In order to build a project containing Svelte files, you need a bundler like Vite, Rollup or Webpack configured, just using tsc won't work. In other words, you can only use tsc for type checking, and for that you should use svelte-check instead.

@curiousdannii
Copy link
Author

curiousdannii commented Oct 10, 2024

Hmm. I think I've been getting myself confused. My setup is only using tsc in order to type check everything, but my tests only run the Node version, so the fact that my browser code can't actually import the svelte components doesn't matter. So never mind.

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

2 participants