slidevjs / slidev

Presentation Slides for Developers
https://sli.dev
MIT License
33.68k stars 1.38k forks source link

"npm run build" ends in error "[vite:esbuild] Transform failed - ERROR: Expected ">" but found "setup" #1844

Open bLuma opened 3 months ago

bLuma commented 3 months ago

Describe the bug

"npm run build" ends in error "[vite:esbuild] Transform failed with 1 error - ERROR: Expected ">" but found "setup"" with just initialized slidev project. Its probably same error as previously encountered in #1808.

Minimal reproduction

Steps to reproduce the behavior:

  1. npm init slidev@latest
  2. npm run build

Environment

  Slidev  v0.49.29

  theme       @slidev/theme-seriph
  css engine  unocss
  entry       c:\Users\r\Downloads\slidevn\slidev\slides.md
vite v5.4.2 building for production...
✓ 340 modules transformed.
x Build failed in 3.42s
[vite:esbuild] Transform failed with 1 error:
C:/Users/r/Downloads/slidevn/slidev/node_modules/@slidev/client/internals/SlideLoading.vue?vue&type=script&setup=true&lang.ts:1:8: ERROR: Expected ">" but found "setup"
file: C:/Users/r/Downloads/slidevn/slidev/node_modules/@slidev/client/internals/SlideLoading.vue?vue&type=script&setup=true&lang.ts:1:8

Expected ">" but found "setup"
1  |  <script setup lang="ts">
   |          ^
2  |  import { onMounted, ref } from 'vue'
3  |

    at failureErrorWithLog (c:\Users\r\Downloads\slidevn\slidev\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15)
    at c:\Users\r\Downloads\slidevn\slidev\node_modules\vite\node_modules\esbuild\lib\main.js:755:50
    at responseCallbacks.<computed> (c:\Users\r\Downloads\slidevn\slidev\node_modules\vite\node_modules\esbuild\lib\main.js:622:9)
    at handleIncomingPacket (c:\Users\r\Downloads\slidevn\slidev\node_modules\vite\node_modules\esbuild\lib\main.js:677:12)
    at Socket.readFromStdout (c:\Users\r\Downloads\slidevn\slidev\node_modules\vite\node_modules\esbuild\lib\main.js:600:7)
    at Socket.emit (node:events:520:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:191:23) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter],
  frame: '\n' +
    '\x1B[33mExpected ">" but found "setup"\x1B[39m\n' +
    '1  |  <script setup lang="ts">\n' +
    '   |          ^\n' +
    "2  |  import { onMounted, ref } from 'vue'\n" +
    '3  |  \n',
  loc: {
    column: 8,
    file: 'C:/Users/r/Downloads/slidevn/slidev/node_modules/@slidev/client/internals/SlideLoading.vue?vue&type=script&setup=true&lang.ts',
    length: 5,
    line: 1,
    lineText: '<script setup lang="ts">',
    namespace: '',
    suggestion: '>'
  },
  code: 'PLUGIN_ERROR',
  plugin: 'vite:esbuild',
  hook: 'transform',
  id: 'C:/Users/r/Downloads/slidevn/slidev/node_modules/@slidev/client/internals/SlideLoading.vue?vue&type=script&setup=true&lang.ts',
  watchFiles: [

Maybe its platform (Windows) related, I tested your "sandbox" environment and know that there build is fine. I'm familiar to Node and react, but not to vue / vite / esbuild, not sure where to look more specifically for error/help with this issue.

Llois41 commented 3 months ago

I don't know if this is helpful but I think this issue is more related to the interaction between vite, esbuild or one of the plugins used to transform the vue code. We get this exact same error in our project (and don't use slidev at all) and saw that the esbuild step in our building/bundling process received the .vue SFC file when it was expecting TypeScript code. But this error occures only occasionally so it is very hard to debug.

However I hope this helps to point in the right direction.

bLuma commented 3 months ago

And I forgot to mention that I have no error when starting dev server or doing export to pdf. Only build operation is failing.

KermanX commented 3 months ago

Possibly https://github.com/vitejs/vite-plugin-vue/issues/431. There is a workaround in https://github.com/dcloudio/uni-preset-vue/issues/102#issuecomment-2251907200. What's the @vitejs/plugin-vue version you're using?

bLuma commented 3 months ago

I have 5.1.2 and ends in error.

| | +-- @vitejs/plugin-vue-jsx@4.0.1 deduped
| | +-- @vitejs/plugin-vue@5.1.2 deduped
| | +-- unplugin-vue-markdown@0.26.2 deduped
| | +-- vite-plugin-vue-server-ref@0.4.2 deduped
| +-- @vitejs/plugin-vue-jsx@4.0.1
| +-- @vitejs/plugin-vue@5.1.2
| +-- unplugin-vue-components@0.27.4
| +-- unplugin-vue-markdown@0.26.2
| +-- vite-plugin-vue-server-ref@0.4.2

Tried mentioned version ~5.0.4, which resulted again in error:

| | +-- @vitejs/plugin-vue-jsx@4.0.1 deduped
| | +-- @vitejs/plugin-vue@5.0.5 overridden
| | +-- unplugin-vue-markdown@0.26.2 deduped
| | +-- vite-plugin-vue-server-ref@0.4.2 deduped
| +-- @vitejs/plugin-vue-jsx@4.0.1
| +-- @vitejs/plugin-vue@5.0.5 overridden
| +-- unplugin-vue-components@0.27.4
| +-- unplugin-vue-markdown@0.26.2
| +-- vite-plugin-vue-server-ref@0.4.2

I tested it also on another computer, where i have windows and it works with plugin-vue 5.1.2. In fact I compared output of "npm ls -a" and i got all packages on same versions on both computers. Yet on one it works and on second still no. To be sure i copied entire project with all installed node modules from working computer to my not working, run build and again got error. So exactly same code works on work computer with Win 10 22H2 and not works on my home computer with Win 11.

And because this looks like some error connected to vite/esbuild feel free to close this issue as this is probably unsolvable by slidev.