The first time you use vite to create a new Vue3 project on Mac, you need to pay attention to your own error records

When executing npm init @vitejs/app

Error:
internal/modules/cjs/loader.js:1089
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
insert image description here
At first I searched for the reason online, thinking that the version of node was too low, but I saw that it was my own version number is 12.1 .xx just crossed the threshold, but the creation of the project was unsuccessful. To be on the safe side, the node version was upgraded to 15.7.0. Tried it, um, still reporting an error. After searching on the Internet for a long time, some people have problems installing vite. If you look closely, it may be because the version of npm is too low. Think about whether this is also caused by yourself, and update the original 6.xx of the npm version to 8.xx. Re-execute npm init @vitejs/app, haha ​​succeeded.

However, the good times didn’t last long. After entering y in Need to install the following packages: create-vite, an error was reported. Finally, I created the project using npm init vite

insert image description here
No error was reported, and the startup was successful.
insert image description here

insert image description here
There are many things that need to be configured by yourself. In the end, it is recommended to follow the official website. The official website uses:
npm init vue@latest

Official website: https://cn.vuejs.org/guide/quick-start.html#with-build-tools

It should be noted that the official website reminds the node version that Node.js of version 15.0 or higher has been installed. I just tried to create a project in the way provided by the official website, and encountered an error, and then upgraded node to the latest stable version 16.17.0, which ran successfully, and the previous 15.7.0 did not work.

1. The version of node must be greater than
the version of node >=12.0.0 (given on the Internet, my own is version 15)

View node version number:
node -v

View all version numbers:
npm view node versions

Upgrade reference:
https://blog.csdn.net/lhz_333/article/details/123477575

2. Remember to upgrade the version of npm. The version I reported earlier was 6.14.15, and the version number after the upgrade is 8.19.2

Check the current version number:
npm --version (npm -v)

Upgrade to the latest version:
sudo npm install npm@latest -g

Guess you like

Origin blog.csdn.net/qq_45989931/article/details/127008304