使用vite创建vue3报错 npm ERR! Could not install from xxxxxxxx it does not contain a package json file

PS G:\vue3> npm init vite-app vue3_test_vite
npm ERR! Could not install from "Files\nodejs\node_cache\_npx\4852" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Program Files\nodejs\node_cache\_logs\2021-12-22T08_21_24_218Z-debug.log
安装 [ 'create-vite-app@latest' ] 失败,错误代码:1

错误原因

node_cache路径存在空格

// 运行指令
npm config get cache
// Program Files名称存在空格
C:\Program Files\nodejs\node_cache

解决方案一

// 运行指令
npm config edit

npm config edit
将带空格的路径改写为:C:\Program~1\nodejs\node_cache

解决方案二

// 运行指令
npm config set cache "C:\Program~1\nodejs\node_cache" --global

再次运行安装指令

npm init vite-app

PS G:\vue3> npm init vite-app vue3_test_vite
npx: 7 安装成功,用时 3.371 秒
Scaffolding project in G:\vue3\vue3_test_vite...

Done. Now run:

  cd vue3_test_vite
  npm install (or `yarn`)

进入目录

 cd .\vue3_test_vite\

运行

npm i 指令

G:\vue3\vue3_test_vite> npm i

> esbuild@0.8.57 postinstall G:\vue3\vue3_test_vite\node_modules\esbuild
> node install.js

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN vue3_test_vite@0.0.0 No description
npm WARN vue3_test_vite@0.0.0 No repository field.
npm WARN vue3_test_vite@0.0.0 No license field.

added 282 packages from 277 contributors in 23.489s

31 packages are looking for funding
  run `npm fund` for details

运行

npm run dev 指令

PS G:\vue3\vue3_test_vite> npm run dev

> vue3_test_vite@0.0.0 dev G:\vue3\vue3_test_vite
> vite

[vite] Optimizable dependencies detected:
vue

  Dev server running at:
  > Network:  http://192.168.x.xx:3000/
  > Local:    http://localhost:3000/

成功

vue3.0 vite
文章参考出处: (https://blog.csdn.net/hellobbw/article/details/108402959).

Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐