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

Passing a seemingly empty type to defineProps with defineDefaults throws an error #5437

Closed
7 tasks done
simonwep opened this issue Oct 27, 2021 · 3 comments
Closed
7 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pending triage

Comments

@simonwep
Copy link

Describe the bug

If the type passed to defineProps in combination with defineDefaults is seemingly empty (either actually empty or the interface used for props extends another but doesn't add any additional types) and the value is stored in a variable an error is thrown.

Reproduction

Considering the following, empty component:

<template></template>

<script setup lang="ts">
interface BaseProps {
    msg: string;
}

interface Props extends BaseProps {}

const props = withDefaults(defineProps<Props>(), {});
</script>

where Props can also be

interface Props {}

or

type Props = {};

or not used at all:

<template>

</template>

<script setup lang="ts">
const props = withDefaults(defineProps<{}>(), {});
</script>

throws an error:

10:25:01 AM [vite] Internal server error: Transform failed with 1 error:
xxx/src/components/HelloWorld.vue:7:26: error: Unexpected "}"
  Plugin: vite:vue
  File: xxx/src/components/HelloWorld.vue
  
  Unexpected "}"
  5  |    expose()
  6  |  
  7  |  const props = __props as  }
     |                            ^
  8  |  
  9  |  
  
      at failureErrorWithLog (xxx/node_modules/esbuild/lib/main.js:1493:15)
      at xxx/node_modules/esbuild/lib/main.js:1282:29
      at xxx/node_modules/esbuild/lib/main.js:629:9
      at handleIncomingPacket (xxx/node_modules/esbuild/lib/main.js:726:9)
      at Socket.readFromStdout (xxx/node_modules/esbuild/lib/main.js:596:7)
      at Socket.emit (node:events:390:28)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10)
      at Pipe.onStreamRead (node:internal/stream_base_commons:199:23)

System Info

System:
    OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 7.67 GB / 31.22 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.11.0 - /usr/local/bin/node
    npm: 8.1.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 95.0.4638.54
  npmPackages:
    @vitejs/plugin-vue: ^1.9.4 => 1.9.4 
    vite: ^2.6.12 => 2.6.12

Used Package Manager

npm

Logs

vite:config bundled config file loaded in 638.70ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-script-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:vue',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  vite:config   },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: { external: [ 'vue', '@vue/server-renderer' ] },
  vite:config   configFile: 'xxx/vite.config.ts',
  vite:config   configFileDependencies: [ 'vite.config.ts' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: {}
  vite:config   },
  vite:config   root: 'xxx',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: 'xxx/public',
  vite:config   cacheDir: 'xxx/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   server: { fs: { strict: undefined, allow: [Array] } },
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: {
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   }
  vite:config } +6ms
vite v2.6.12 building for production...
transforming (6) src/App.vue  vite:esbuild esbuild error with options used:  {
  sourcemap: false,
  sourcefile: 'xxx/src/components/HelloWorld.vue',
  loader: 'ts',
  tsconfigRaw: { compilerOptions: { useDefineForClassFields: true } }
} +0ms
✓ 9 modules transformed.
[vite:vue] Transform failed with 1 error:
xxx/src/components/HelloWorld.vue:7:26: error: Unexpected "}"
file: xxx/src/components/HelloWorld.vue:7:26

Unexpected "}"
5  |    setup(__props: any) {
6  |  
7  |  const props = __props as  }
   |                            ^
8  |  
9  |  

error during build:
Error: Transform failed with 1 error:
xxx/src/components/HelloWorld.vue:7:26: error: Unexpected "}"
    at failureErrorWithLog (xxx/node_modules/esbuild/lib/main.js:1493:15)
    at xxx/node_modules/esbuild/lib/main.js:1282:29
    at xxx/node_modules/esbuild/lib/main.js:629:9
    at handleIncomingPacket (xxx/node_modules/esbuild/lib/main.js:726:9)
    at Socket.readFromStdout (xxx/node_modules/esbuild/lib/main.js:596:7)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:199:23)

Validations

@bluwy
Copy link
Member

bluwy commented Mar 28, 2022

I can still reproduce this with plugin-vue 2.2.4. Here's a stackblitz repro: https://stackblitz.com/edit/vitejs-vite-crwqk9?file=src%2Fcomponents%2FHelloWorld.vue&terminal=dev

@bluwy bluwy added the p3-minor-bug An edge case that only affects very specific usage (priority) label Mar 28, 2022
@sapphi-red
Copy link
Member

@bluwy I found this is a duplicate of #7343 which is reported to vuejs/core by vuejs/core#5613.

@bluwy
Copy link
Member

bluwy commented Mar 30, 2022

Ah thanks @sapphi-red. Let's move the discussion over there then.

@bluwy bluwy closed this as completed Mar 30, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pending triage
Projects
None yet
Development

No branches or pull requests

4 participants