slidev icon indicating copy to clipboard operation
slidev copied to clipboard

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

Open bLuma opened this issue 1 year ago • 4 comments

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.

bLuma avatar Aug 27 '24 08:08 bLuma

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.

Llois41 avatar Aug 28 '24 06:08 Llois41

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

bLuma avatar Aug 28 '24 06:08 bLuma

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?

kermanx avatar Aug 28 '24 06:08 kermanx

I have 5.1.2 and ends in error.

| | +-- @vitejs/[email protected] deduped
| | +-- @vitejs/[email protected] deduped
| | +-- [email protected] deduped
| | +-- [email protected] deduped
| +-- @vitejs/[email protected]
| +-- @vitejs/[email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]

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

| | +-- @vitejs/[email protected] deduped
| | +-- @vitejs/[email protected] overridden
| | +-- [email protected] deduped
| | +-- [email protected] deduped
| +-- @vitejs/[email protected]
| +-- @vitejs/[email protected] overridden
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]

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.

bLuma avatar Aug 28 '24 13:08 bLuma