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

Table of contents

1. Problem description:

Two, the reason

 3. Solutions


1. Problem description:

When learning vue3.0 (  Vue.js - Progressive JavaScript framework | Vue.js ), I have been using my home computer. The project has been built and run without problems. The company recently used vue3.0 to write projects

npm init vue@latest —> npm install is ok, and when npm run dev, the error is as follows:

failed to load config from F:\vue\vuejs3.0\vite.config.ts
error when starting dev server:     
Error: Cannot find module 'node:url'
Require stack:
- F:\vue\vuejs3.0\vite.config.ts    
- F:\vue\vuejs3.0\node_modules\vite\dist\node\chunks\dep-561c5231.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (F:\vue\vuejs3.0\vite.config.ts:32:23)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object._require.extensions..js (file:///F:/vue/vuejs3.0/node_modules/vite/dist/node/chunks/dep-561c5231.js:62739:20)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)

Two, the reason

Because the node version used by the company is 14.15.0 lower than 15.0.0

Node version requirements: Quick start | Vue.js

 3. Solutions

Install node version equal to or greater than 15.0.0, then npm run dev

Remarks: Because sometimes our different environments have different requirements for nodejs versions, we can use the nvm tool to manage and switch node.js versions

Nvm related can view this article:

Summary of installation, use and common problems of nvm

Guess you like

Origin blog.csdn.net/qq_35432904/article/details/126486267