Subscribe on changes!

`Missing initializer in const declaration.` error on defineProps type imported from node_modules

avatar
May 11th 2023

Vue version

3.3

Link to minimal reproduction

https://stackblitz.com/edit/vue3-vite-typescript-starter-tk9ebx?file=src/App.vue

Steps to reproduce

The error is presented by Vite immediately upon opening the project.

If you comment out the TestComponent and uncomment the TestComponentLocal there is no error.

This same error occurs when trying to build the project as well.

What is expected?

In TestComponent, the type QSelectProps is being imported from the "quasar" library and is being used as the type in defineProps.

In TestComponentLocal, that exact type QSelectProps has been copy/pasted into a local .ts file. So, the only difference is the location of the type definition.

TestComponentLocal works and I would expect TestComponent to work in the same way.

What is actually happening?

TestComponent fails to render with this error from the vite dev server.

Error in error handler:
Error: offset is longer than source length! offset 416615 > length 349
    at numberToPos (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:12128:15)
    at formatError (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:42679:35)
    at TransformContext.error (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:42657:19)
    at Object.transform (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:42938:25)
    at async loadAndTransform (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:53401:29)

Missing initializer in const declaration. (14207:45)
Error in error handler:
Error: offset is longer than source length! offset 416615 > length 349
    at numberToPos (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:12128:15)
    at formatError (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:42679:35)
    at TransformContext.error (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:42657:19)
    at Object.transform (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:42938:25)
    at async loadAndTransform (file://file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:53401:29)

11:50:27 AM [vite] Internal server error: Missing initializer in const declaration. (14207:45)
  Plugin: vite:vue
  File: /home/projects/vue3-vite-typescript-starter-tk9ebx/src/components/TestComponent.vue:14207:45
      at instantiate (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:653:32)
      at constructor (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:946:12)
      at TypeScriptParserMixin.raise (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:3270:19)
      at TypeScriptParserMixin.parseVar (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:13201:16)
      at TypeScriptParserMixin.parseVarStatement (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:13032:10)
      at TypeScriptParserMixin.parseVarStatement (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:9364:31)
      at TypeScriptParserMixin.parseStatementContent (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:12629:23)
      at TypeScriptParserMixin.parseStatementContent (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:9398:18)
      at TypeScriptParserMixin.parseStatementLike (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:12549:17)
      at TypeScriptParserMixin.parseStatementListItem (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:12529:17)

I also get this error when attempting to build the project.

[vite:vue] Missing initializer in const declaration. (14207:45)
file: /home/projects/vue3-vite-typescript-starter-tk9ebx/src/components/TestComponent.vue:14207:45
error during build:
SyntaxError: Missing initializer in const declaration. (14207:45)
    at instantiate (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:653:32)
    at constructor (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:946:12)
    at TypeScriptParserMixin.raise (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:3270:19)
    at TypeScriptParserMixin.parseVar (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:13201:16)
    at TypeScriptParserMixin.parseVarStatement (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:13032:10)
    at TypeScriptParserMixin.parseVarStatement (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:9364:31)
    at TypeScriptParserMixin.parseStatementContent (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:12629:23)
    at TypeScriptParserMixin.parseStatementContent (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:9398:18)
    at TypeScriptParserMixin.parseStatementLike (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:12549:17)
    at TypeScriptParserMixin.parseStatementListItem (file:///home/projects/vue3-vite-typescript-starter-tk9ebx/node_modules/@babel/parser/lib/index.js:12529:17)

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz
    Memory: 30.10 GB / 63.73 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 9.6.6 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (113.0.1774.35)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    vue: ^3.2.47 => 3.3.1

Any additional comments?

I'm trying to wrap a component library component in a custom component, and using the library's prop types to define my customer component's properties.

This currently works if I copy out the props type into a file in the local repository, but not by importing it directly from node_modules.

avatar
May 12th 2023

Me too!

avatar
May 12th 2023

same here