Home  >  Article  >  Web Front-end  >  Linux failed to create vue project

Linux failed to create vue project

PHPz
PHPzOriginal
2023-05-24 14:05:37716browse

I recently tried to create a Vue project on a Linux system, but encountered some problems. After trying various setup and installation methods, I finally succeeded. In this article, I will share my experience with this problem and how to solve it.

Problem description

I am using Ubuntu 18.04 version and just installed Node.js and npm package manager. Then, I executed the following command to install the Vue CLI:

npm install -g @vue/cli

When I tried to create a new Vue project with the following command:

vue create my-project

I encountered the following error:

internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module '/usr/lib/node_modules/@vue/cli-service/bin/vue-cli-service.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:49:12)
    at internal/main/run_main_module.js:11:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Cause Analysis

The reason for this error is that the @vue/cli-service module cannot be found. @vue/cli-service is one of the dependent modules of Vue CLI. Without this module, Vue projects cannot be created normally.

Solution

  1. Uninstall Vue CLI

First, we need to uninstall the originally installed Vue CLI. You can use the following command:

npm uninstall -g vue-cli
npm uninstall -g @vue/cli
  1. Install nvm

nvm (Node Version Manager) is a tool that can install and manage multiple Node.js versions on the same computer. Because different versions of Node.js may need to be used in dependent modules of Vue CLI, we need to install nvm.

Use the following command to install nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
  1. Install Node.js

After installing nvm, we can use nvm to install different versions of Node .js. In this example, we will install the latest version of Node.js.

First, use the following command to list the known Node.js versions:

nvm ls-remote

Then, we can use the following command to install the latest version of Node.js:

nvm install node

After installing Node.js, we need to set the default version of Node.js. Set up using the following command:

nvm alias default node
  1. Reinstall Vue CLI

After installing Node.js, we can reinstall Vue CLI:

npm install -g @vue/cli

Now We can create a new Vue project:

vue create my-project

Now you should be able to create the Vue project normally. If the problem persists, you can try restarting the terminal or computer to ensure that the relevant environment variables are loaded correctly.

Summary

When creating a Vue project in Linux, you need to clearly depend on the Node.js version, and you need to pay attention to the path and installation location of the relevant modules. If you encounter a problem, you can try to uninstall and reinstall the relevant software, or check the relevant error message to solve the problem. Through this article, I hope to help developers who encounter problems when creating Vue projects in a Linux environment.

The above is the detailed content of Linux failed to create vue project. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn