Vue CLI安装及项目启动报错求助(Node.js v13.8.0/Vue CLI v4.2.2)
Hey there, let's work through each of your problems step by step to get your Vue.js environment up and running smoothly.
1. Permission Error When Installing Vue CLI Globally
The EACCES error pops up because your user account doesn't have write permissions to the system-level Node.js modules directory (/usr/local/lib/node_modules/). Here are a few safe ways to fix this:
Option 1: Use a User-Specific npm Directory (Recommended)
This avoids messing with system-level permissions entirely:
- First, create a dedicated directory for global npm packages in your user folder:
mkdir ~/.npm-global - Configure npm to use this new directory as its global prefix:
npm config set prefix '~/.npm-global' - Add this directory to your shell's PATH (add this line to your
~/.bash_profileor~/.zshrcfile, depending on which shell you use):export PATH=~/.npm-global/bin:$PATH - Reload your shell configuration to apply the change:
source ~/.bash_profile # Use source ~/.zshrc if you use Zsh - Now you can install Vue CLI globally without any permission issues:
npm install -g @vue/cli
Option 2: Use sudo (Temporary, Less Recommended)
If you need a quick fix, you can run the install command with sudo (note: this gives the command system-level access, so use this cautiously):
sudo npm install -g @vue/cli
Option 3: Use nvm to Manage Node.js (Best Long-Term Solution)
nvm (Node Version Manager) installs Node.js directly in your user directory, eliminating permission problems from the start:
- Install nvm by downloading the official install script from the nvm project and running it in your terminal.
- Reload your shell, then install and activate your desired Node.js version:
nvm install 13.8.0 nvm use 13.8.0 - Now install Vue CLI globally without any permission errors:
npm install -g @vue/cli
2. gyp Error: No Xcode or CLT Version Detected
This error happens because node-gyp (a tool used to compile native modules like fsevents) requires Xcode Command Line Tools. Here's how to resolve it:
- Install the Command Line Tools directly from your terminal:
xcode-select --install - Follow the pop-up prompts to complete the installation.
- If you already have the tools installed but still get the error, reset the xcode-select path:
sudo xcode-select --reset - Finally, accept the Xcode license agreement (required for some tools to work properly):
sudo xcodebuild -license accept
After completing these steps, retry creating your Vue project with vue create nameofproject—the gyp error should disappear.
3. npm run serve: No Such File or Directory (package.json)
This one's a simple fix: you're running the command from the wrong directory! The package.json file lives inside your project folder (projet), but you executed npm run serve from the parent excli directory.
Fix it by:
- First navigating into your project folder:
cd projet - Then running the serve command:
npm run serve
That should start your Vue development server without any issues.
内容的提问来源于stack exchange,提问作者Cédric Teixeira Alves

