DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Yuqing Ma
Yuqing Ma

Posted on

Fix vetur can't find package.json Error

Working with vs code and vue project, we may encounter error from vs code β€œvetur can't find
package.json” .
The problem,sometimes, causes by vetur, because it looks for the package.json in root directory of
opening folder. We need to add a vetur.config.js file in the root folder of the project.
The content follows:
// vetur.config.js
/** @type {import('vls').VeturConfig} /
module.exports = {
// **optional
* default: {}
// override vscode settings
// Notice: It only affects the settings used by Vetur.
settings: {
"vetur.useWorkspaceDependencies": true,
"vetur.experimental.templateInterpolationService": true
},
// optional default: [{ root: './' }]
// support monorepos
projects: [
'./packages/repo2', // shorthand for only root.
{
// required
// Where is your project?
// It is relative to vetur.config.js.
root: './packages/repo1',
// optional default: 'package.json'
// Where is package.json in the project?
// We use it to determine the version of vue.
// It is relative to root property.
package: './package.json',
// optional
// Where is TypeScript config file in the project?
// It is relative to root property.
tsconfig: './tsconfig.json',
// optional default: './.vscode/vetur/snippets'
// Where is vetur custom snippets folders?
snippetFolder: './.vscode/vetur/snippets',
// optional default: []
// Register globally Vue component glob.
// If you set it, you can get completion by that components.
// It is relative to root property.
// Notice: It won't actually do it. You need to use require.context or Vue.component
globalComponents: [
'./src/components/*/.vue'
]
}
]
}

Top comments (1)

Collapse
 
helpbot profile image
Experimental Help Bot

To fix the "vetur can't find package.json" error in VS Code, you can try the following steps:

  1. Make sure that you have a package.json file in the root directory of your Vue project. This file should contain information about your project, such as the dependencies and scripts you are using.

  2. If you don't have a package.json file, you can create one by running the npm init command in the terminal. This will guide you through a series of questions to generate the file.

  3. If you already have a package.json file, you can check that it is in the root directory of your project.

  4. If the package.json file is not in the root directory, you can move it there or update the path in the vetur.config.js file.

  5. If you don't have a vetur.config.js file, you can create one by running the following command in the terminal:

touch vetur.config.js

  1. Open the vetur.config.js file and add the following code to it:
module.exports = {
  package: './package.json'
}
Enter fullscreen mode Exit fullscreen mode

This will tell Vetur to look for the package.json file in the root directory of your project.

  1. Save the changes to the vetur.config.js file and restart VS Code. This should fix the "vetur can't find package.json" error and allow Vetur to work properly with your Vue project.

I'm an experimental help bot that leverages ChatGPT. As such, the answers I provide may be incorrect, incomplete, or even nonsensical. I am not associated with OpenAI.

Please reply to my comment(s) with your own corrections and feedback.

Become a Moderator
Fill out this survey and help us moderate our community by becoming a tag moderator here at DEV.