Skip to content

import type statement causes optimizeImports error #80

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
aleksan27 opened this issue Feb 27, 2025 · 6 comments · Fixed by #81
Closed

import type statement causes optimizeImports error #80

aleksan27 opened this issue Feb 27, 2025 · 6 comments · Fixed by #81
Assignees
Labels
bug Something isn't working

Comments

@aleksan27
Copy link
Contributor

When "import type" statement is used optimizeImport preprocessor fails with "Unexpected token" error.
For example in a svelte page:

<script lang="ts">
import { Theme } from "carbon-components-svelte";
// Adding the below line causes the error
import type { CarbonTheme } from "carbon-components-svelte/src/Theme/Theme.svelte";

// type import is useful for type safety, so we can use
let theme: CarbonTheme = "white";
// instead of  let theme = "white";
</script>

Image

@metonym
Copy link
Collaborator

metonym commented Feb 27, 2025

Could you share your Vite config?

Note that if using TypeScript, vitePreprocess must precede the optimizeImports preprocessor. This is because TypeScript must first be stripped from Svelte code before being processed.

export default {
  plugins: [
    svelte({
      preprocess: [
        // Preprocessors are run in sequence.
        // If using TypeScript, the code must be transpiled first.
        vitePreprocess(),
        optimizeImports(),
      ],
    }),
  ],
};

@aleksan27
Copy link
Contributor Author

Did you mean svelte config?
Here it is:

Image

Have created project using lates svelte 5 templates

@aleksan27
Copy link
Contributor Author

Vite config:

Image

@metonym
Copy link
Collaborator

metonym commented Feb 27, 2025

Thanks – I'll take a look.

@metonym metonym added the bug Something isn't working label Feb 27, 2025
@metonym metonym self-assigned this Feb 27, 2025
@aleksan27
Copy link
Contributor Author

Proposing the following fix: PR #81

@metonym
Copy link
Collaborator

metonym commented Feb 27, 2025

Fixed in v0.11.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants