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

Error when using angle-bracket syntax in typescript #1063

Closed
wattanx opened this issue Jan 13, 2024 · 0 comments · Fixed by #1064
Closed

Error when using angle-bracket syntax in typescript #1063

wattanx opened this issue Jan 13, 2024 · 0 comments · Fixed by #1064

Comments

@wattanx
Copy link
Collaborator

wattanx commented Jan 13, 2024

Environment


  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 2.17.2
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: npm@9.4.2
  • Builder: webpack
  • User Config: serverHandlers, devServerHandlers, devServer, typescript, nitro, bridge, buildModules
  • Runtime Modules: -
  • Build Modules: (), @nuxt/bridge@3.0.0

Reproduction

https://stackblitz.com/edit/github-qrwhz3

Describe the bug

Error when using angle-bracket syntax in typescript. (e.g. const strLength: number = (<string>value).length;)
This is because @babel/plugin-transform-typescript has isTSX in its option.

in ./pages/index.vue?vue&type=script&setup=true&lang=ts (./node_modules/unplugin/dist/webpack/loaders/transform.js?unpluginName=nuxt%3Aimports-transform!./node_modules/unplugin/dist/webpack/loaders/transform.js?unpluginName=nuxt-legacy-vue-transform!./node_modules/babel-loader/lib??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./node_modules/unplugin/dist/webpack/loaders/transform.js?unpluginName=nuxt-legacy-capi-key-transform!./pages/index.vue?vue&type=script&setup=true&lang=ts)
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/projects/github-qrwhz3/pages/index.vue: Unexpected token, expected "}" (10:14)

   8 | const strLength: number = (<string>value).length;
   9 |
> 10 | return { __sfc: true,value, strLength }
     |               ^
  11 | }
  12 |
  13 | })
    at constructor (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:356:19)
    at TypeScriptParserMixin.raise (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:3223:19)
    at TypeScriptParserMixin.unexpected (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:3253:16)
    at TypeScriptParserMixin.expect (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:3585:28)
    at TypeScriptParserMixin.jsxParseExpressionContainer (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:6797:10)
    at TypeScriptParserMixin.jsxParseElementAt (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:6871:36)
    at TypeScriptParserMixin.jsxParseElement (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:6915:17)
    at TypeScriptParserMixin.parseExprAtom (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:6927:19)
    at TypeScriptParserMixin.parseExprSubscripts (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:10857:23)
    at TypeScriptParserMixin.parseUpdate (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:10840:21)

The workaround is to use as instead of angle-bracket syntax.

Additional context

No response

Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant