[英]vuejs sample app npm run dev not working throwing Error: Cannot find module 'node:url'
I am new to vuejs I am following the below steps to create my vue js app in the local system.我是 vuejs 的新手,我正在按照以下步骤在本地系统中创建我的 vue js 应用程序。
Step:步:
npm init vue@latest
npm init vue@latest
✔ Project name: … VueDemo ✔ Add TypeScript? ✔ 项目名称:... VueDemo ✔ 添加 TypeScript? … No / Yes ✔ Add JSX Support?
… 否/是 ✔ 添加 JSX 支持? … No / Yes ✔ Add Vue Router for Single Page Application development?
… 否/是 ✔ 为单页应用程序开发添加 Vue 路由器? … No / Yes ✔ Add Pinia for state management?
… 否/是 ✔ 添加 Pinia 进行状态管理? … No / Yes ✔ Add Vitest for Unit testing?
… 否/是 ✔ 为单元测试添加 Vitest? … No / Yes ✔ Add Cypress for both Unit and End-to-End testing?
… 否/是 ✔ 为单元和端到端测试添加赛普拉斯? … No / Yes ✔ Add ESLint for code quality?
… 否/是 ✔ 添加 ESLint 以提高代码质量? … No / Yes ✔ Add Prettier for code formatting?
… 否 / 是 ✔ 为代码格式化添加 Prettier? … No / Yes
……不/是
Scaffolding project in./ VueDemo Done.脚手架项目在./VueDemo完成。
cd VueDemo npm install npm run dev cd VueDemo npm install npm run dev
It's throwing the following error in the console:它在控制台中抛出以下错误:
failed to load config from /Users/ashok/MyStudy/Vue/VueDemo/vite.config.js error when starting dev server: Error: Cannot find module 'node:url' Require stack:
启动开发服务器时无法从/Users/ashok/MyStudy/Vue/VueDemo/vite.config.js 错误加载配置:错误:找不到模块'node:url'需要堆栈:
- /Users/ashok/MyStudy/Vue/VueDemo/vite.config.js
/Users/ashok/MyStudy/Vue/VueDemo/vite.config.js
- /Users/ashok/MyStudy/Vue/VueDemo/node_modules/vite/dist/node/chunks/dep-0fc8e132.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15) at Function.Module._load (internal/modules/cjs/loader.js:745:27) at Module.require (internal/modules/cjs/loader.js:961:19) at require (internal/modules/cjs/helpers.js:92:18) at Object.
/Users/ashok/MyStudy/Vue/VueDemo/node_modules/vite/dist/node/chunks/dep-0fc8e132.js 在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15) 在功能。 Module._load (internal/modules/cjs/loader.js:745:27) 在 Module.require (internal/modules/cjs/loader.js:961:19) 在 require (internal/modules/cjs/helpers.js: 92:18) 在对象处。 (/Users/ashok/MyStudy/Vue/VueDemo/vite.config.js:31:23) at Module._compile (internal/modules/cjs/loader.js:1072:14) at Object._require.extensions.
(/Users/ashok/MyStudy/Vue/VueDemo/vite.config.js:31:23) 在 Module._compile (internal/modules/cjs/loader.js:1072:14) 在 Object._require.extensions。 [as.js] (file:///Users/ashok/MyStudy/Vue/VueDemo/node_modules/vite/dist/node/chunks/dep-0fc8e132.js:63096:24) at Module.load (internal/modules/cjs/loader.js:937:32) at Function.Module._load (internal/modules/cjs/loader.js:778:12) at Module.require (internal/modules/cjs/loader.js:961:19)
[as.js] (file:///Users/ashok/MyStudy/Vue/VueDemo/node_modules/vite/dist/node/chunks/dep-0fc8e132.js:63096:24) 在 Module.load (internal/modules/ cjs/loader.js:937:32) 在 Function.Module._load (internal/modules/cjs/loader.js:778:12) 在 Module.require (internal/modules/cjs/loader.js:961:19)
Package.json file: Package.json 文件:
{
"name": "vuedemo",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview --port 4173"
},
"dependencies": {
"vue": "^3.2.37"
},
"devDependencies": {
"@vitejs/plugin-vue": "^3.0.1",
"vite": "^3.0.4"
}
}
vite.config.js: vite.config.js:
import { fileURLToPath, URL } from 'node:URL
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
Just upgrade your node to the latest, remove node_modules
, and run npm install
again.只需将您的节点升级到最新版本,删除
node_modules
,然后再次运行npm install
。
Try using:尝试使用:
node version 18.12.1 or above and npm version 9.2.0 or above节点版本 18.12.1 或更高版本和 npm 版本 9.2.0 或更高版本
after that try:在那之后尝试:
npm install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.