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

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

Closed
Basaingeal opened this issue May 11, 2023 · 2 comments

Comments

@Basaingeal
Copy link

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.

@an501920078
Copy link

Me too!

@yanbowe
Copy link

yanbowe commented May 12, 2023

same here

@github-actions github-actions bot locked and limited conversation to collaborators Sep 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants