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

TypeScript estree import error #15136

Closed
Leniorko opened this issue Jul 20, 2023 · 2 comments
Closed

TypeScript estree import error #15136

Leniorko opened this issue Jul 20, 2023 · 2 comments
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@Leniorko
Copy link

Leniorko commented Jul 20, 2023

Environments:

  • Prettier Version: 3.0.0
  • Running Prettier via: Browser API
  • Runtime: Chrome V114
  • Operating System: Linux
  • Prettier plugins (if any): None? Probably.

Steps to reproduce:

I'm writing some application with svelte and TypeScript. And there is a component that is supposed to print code that it was passed from props. Code is usually not formatted so I'm using Prettier to format it at runtime and highlight.js to paint it.

It works perfectly fine. I imported firstly babel plugin and error in the browser said that I also need estree. I imported it and error disappeared and there is no more errors in browser. But typescript now throws an error about estree import: File '.../node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/estree.d.ts' is not a module.ts(2306)

I suppose error happens because estree.d.ts is empty.

Just in case here is an entire code of the component:

<script lang="ts">
  import hljs from "highlight.js";
  import type { LanguageFn } from "highlight.js";
  import type { Language } from "./CodeBlock.type";
  import { onMount } from "svelte";
  import "highlight.js/styles/stackoverflow-dark.css";
  import * as Prettier from "prettier";
  import BabelPlugin from "prettier/plugins/babel";
  import EsTreePlugin from "prettier/plugins/estree";

  export let codeBlock: string;
  let formattedCode: string = "";
  export let language: Language = "javascript";

  $: Prettier.format(codeBlock, {
    parser: "babel",
    plugins: [BabelPlugin, EsTreePlugin],
  }).then((result) => {
    formattedCode = result;
    console.log(result);
  });

  onMount(() => {
    hljs.registerLanguage(language, (hljs) => {
      return hljs.getLanguage(language) as ReturnType<LanguageFn>;
    });
  });

  let highlightedCode: string;

  $: highlightedCode = hljs.highlight(formattedCode, {
    language,
  }).value;
</script>

<code class="code hljs">
  {@html highlightedCode}
</code>

<style>
  .code {
    width: 100%;
    display: block;
    padding: 8px;
    white-space: pre-wrap;
  }
</style>

Expected behavior:

Proper import without any errors.

Actual behavior:

TypeScript error has type error, but works fine.

@auvred
Copy link
Contributor

auvred commented Jul 21, 2023

Hi, this issue is already fixed in #15018

@Leniorko
Copy link
Author

Hi, this issue is already fixed in #15018

Checked PR, looks like it. I'll be waiting for the next update then. Thank you.

@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Nov 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

2 participants