繁体   English   中英

Npm 无法使用 npm init 安装包

[英]Npm cannot install packages with npm init

我正在尝试使用以下命令安装下一个 js:

 $c:/Desktop/next: npm init next-app nextjs-blog

这给了我一个错误

npm ERR! Could not install from "Dahal\AppData\Roaming\npm-cache\_npx\14636" as it does not contain a package.json file.

注意:我的用户是C:/Users/Sunita Dahal但它似乎在Dahal内部。 但我能够安装全局包。 reinstalling & cleaning cache doesnt work work me

这是完整的错误日志:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'create-next-app@latest',
1 verbose cli   '--global',
1 verbose cli   '--prefix',
1 verbose cli   'C:\\Users\\Sunita',
1 verbose cli   'Dahal\\AppData\\Roaming\\npm-cache\\_npx\\14636',
1 verbose cli   '--loglevel',
1 verbose cli   'error',
1 verbose cli   '--json'
1 verbose cli ]
2 info using npm@6.14.4
3 info using node@v12.16.3
4 verbose npm-session a7314bdab23f336e
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for file:Dahal\AppData\Roaming\npm-cache\_npx\14636 Could not install from "Dahal\AppData\Roaming\npm-cache\_npx\14636" as it does not contain a package.json file.
8 http fetch GET 304 https://registry.npmjs.org/create-next-app 167ms (from cache)
9 silly pacote tag manifest for create-next-app@latest fetched in 190ms
10 timing stage:rollbackFailedOptional Completed in 1ms
11 timing stage:runTopLevelLifecycles Completed in 204ms
12 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\Sunita Dahal\Desktop\next\Dahal\AppData\Roaming\npm-cache\_npx\14636\package.json'
13 verbose cwd C:\Users\Sunita Dahal\Desktop\next
14 verbose Windows_NT 10.0.18362
15 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "create-next-app@latest" "--global" "--prefix" "C:\\Users\\Sunita" "Dahal\\AppData\\Roaming\\npm-cache\\_npx\\14636" "--loglevel" "error" "--json"
16 verbose node v12.16.3
17 verbose npm  v6.14.4
18 error code ENOLOCAL
19 error Could not install from "Dahal\AppData\Roaming\npm-cache\_npx\14636" as it does not contain a package.json file.
20 verbose exit [ 1, true ]

解决方案更改我的缓存路径为我解决了这个问题。 npm config set cache C:\tmp\nodejs\npm-cache --global more at: https://github.com/zkat/npx/

因此命令npm init将初始化一个新项目并生成一个包含项目相关信息的package.json文件。 该命令可以在任何地方运行。 当您想创建自己的新项目时,请使用npm init

但是, npm install ,或npm i ,将在现有项目目录的package.Z46ZDEEC76ECDF35FCA5D46的package.json目录下安装项目相关的依赖项。 您还可以使用npm i package_name_here将新的 package 安装到当前项目。 该命令必须在具有有效package.json的现有项目目录中运行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM