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

"Cannot read property 'vue' of undefined" when there's no "dependencies" in package.json #2632

Closed
4 tasks
scrollbar-ww opened this issue Jan 10, 2021 · 3 comments
Labels

Comments

@scrollbar-ww
Copy link

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform:
  • Vetur version: 0.31.3
  • VS Code version: 1.52.1

Source

"vueVersion.ts":

export function inferVueVersion(packagePath: string | undefined): VueVersion {
  const packageJSONPath = packagePath;
  try {
    if (!packageJSONPath) {
      throw new Error(`Can't find package.json in project`);
    }
    const packageJSON = packageJSONPath && JSON.parse(readFileSync(packageJSONPath, { encoding: 'utf-8' }));
    const vueDependencyVersion = packageJSON.dependencies.vue || packageJSON.devDependencies.vue;
`
@yoyo930021
Copy link
Member

We need to infer vue version for some features.

@scrollbar-ww
Copy link
Author

some component lib doesn't have "dependencies", all external dependencies are in "devDependencies"。
so,it's a little earlier to throw the error.
you should wrote like this:
const vueDependencyVersion = packageJSON.dependencies?.vue || packageJSON.devDependencies?.vue;
if got undefined, throw error.

@yoyo930021
Copy link
Member

Thanks @scrollbar-ww.
Nice catch.

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

No branches or pull requests

2 participants