vue3.0 runs npm run dev and reports an error Cannot find module node:url

vue3.0 runs npm run dev and reports an error Cannot find module

Problem background

Recently, I used vue3.0 to write a project. npm init vue@latest —> npm install is all normal. When npm run dev, the error is reported as follows:

failed to load config from F:\code\testVue\vue-demo\vite.config.js
error when starting dev server:
Error: Cannot find module 'node:url'
Require stack:
- F:\code\testVue\vue-demo\vite.config.js
- F:\code\testVue\vue-demo\node_modules\vite\dist\node\chunks\dep-bb8a8339.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)

problem analysis

Because the node version used is 14.15.1 lower than 15.0.0, install the node version equal to or greater than 15.0.0, and then npm run dev.

problem solved

Different environments have different requirements for the nodejs version. We can use the nvm tool to manage and switch the node.js version.

(1) nvm download: https://nvm.uihtm.com/

(2) nvm command prompt

nvm arch:显示node是运行在32位还是64位。
nvm install <version> [arch] :安装node, version是特定版本也可以是最新稳定版本latest。可选参数arch指定安装32位还是64位版本,默认是系统位数。可以添加--insecure绕过远程服务器的SSL。
nvm list [available] :显示已安装的列表。可选参数available,显示可安装的所有版本。list可简化为ls。
nvm on :开启node.js版本管理。
nvm off :关闭node.js版本管理。
nvm proxy [url] :设置下载代理。不加可选参数url,显示当前代理。将url设置为none则移除代理。
nvm node_mirror [url] :设置node镜像。默认是https://nodejs.org/dist/。如果不写url,则使用默认url。设置后可至安装目录settings.txt文件查看,也可直接在该文件操作。
nvm npm_mirror [url] :设置npm镜像。https://github.com/npm/cli/archive/。如果不写url,则使用默认url。设置后可至安装目录settings.txt文件查看,也可直接在该文件操作。
nvm uninstall <version> :卸载指定版本node。
nvm use [version] [arch] :使用制定版本node。可指定32/64位。
nvm root [path] :设置存储不同版本node的目录。如果未设置,默认使用当前目录。
nvm version :显示nvm版本。version可简化为v。

(3) Install node.js version

1) nvm list available displays a partial list of downloadable versions

Insert image description here

2) nvm install 16.19.0 installs the specified version (nvm install latest installs the latest version)

Note: command line switching (note:Please switch to the domestic image before installing the node version, otherwise it will be very slow)
Alibaba Cloud Mirror

nvm npm_mirror https://npmmirror.com/mirrors/npm/
nvm node_mirror https://npmmirror.com/mirrors/node/

3) After the installation is complete, check the installed version

nvm list
Insert image description here

4) Switch node version

nvm use 16.19.0
Insert image description here

3) Re-run npm run dev and successfully run the vue3 project
Insert image description here

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_39033300/article/details/134033316