Skip to content

fix: build error when script setup has lang="ts"#69

Open
YuyaItabashi3594 wants to merge 1 commit intounplugin:mainfrom
YuyaItabashi3594:main
Open

fix: build error when script setup has lang="ts"#69
YuyaItabashi3594 wants to merge 1 commit intounplugin:mainfrom
YuyaItabashi3594:main

Conversation

@YuyaItabashi3594
Copy link
Copy Markdown

this PR fixes #53

Description

This PR solves that esbuild transforms markdown twice when <script setup lang="ts"> is in markdown.
#53 is easily reproduced if you add <script setup lang="ts"> in examples/vite/README.md` and build.

Situation and Debugging

I use this package for my blog,and I face same issue as #53 . Because I thought this is the opportunity to start contributing, I started debugging.
First,I checked this code in markdown.ts. I added debugging codes in node_modules in my repo that export code as .vue file.Then I found:

  • I have 5 markdown files but 1 was missing
  • the markdown had lang="ts" was exported twice. The one was like <template><div class="markdown-body"><p>import { defineComponent as _defineComponent } from ‘vue’ and the other was clean same as other md files.
    const code = [
      `<template>${html}</template>`,
      ...scripts.map(i => i.trim()).filter(Boolean),
      ...customBlocks.blocks,
    ].join('\n')

Next,I checked transform in unpluginFactory. After several AI generating,I found transforming markdown file with query like README.md?vue&type=script&setup=true&lang.ts:1:15 caused this error. I added if sentence not to run markdownToVue when that markdown is already transformed.

Linked Issues

Additional context

Solutions

I don't fully understand how esbuild/vite work, so there will be better solution. My code looks smell as it solves too honesty.

Others

As my profile this is my 1st contribution,and due to my low development skill I'm afraid this PR might be considered as AI slop. I appreciate if you find better solutions to address this issue,or improve this PR.

How I used AI

I used Gemini for following things:

  • To make debug codes
  • To find where the problem is
  • To make fixes,and learn why it fixes.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

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

Successfully merging this pull request may close these issues.

script setup does not build when using TypeScript flavour

1 participant