我正在尝试使用以下命令安装下一个js:
$c:/Desktop/next: npm init next-app nextjs-blog
这给了我一个错误
npm ERR! Could not install from "DahalAppDataRoamingnpm-cache_npx14636" 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:DahalAppDataRoamingnpm-cache_npx14636 Could not install from "DahalAppDataRoamingnpm-cache_npx14636" 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:UsersSunita DahalDesktopnextDahalAppDataRoamingnpm-cache_npx14636package.json'
13 verbose cwd C:UsersSunita DahalDesktopnext
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 "DahalAppDataRoamingnpm-cache_npx14636" as it does not contain a package.json file.
20 verbose exit [ 1, true ]
解决方案更改我的缓存路径为我解决了这个问题。npm config set cache C:tmpnodejsnpm-cache --global
更多内容: https://github.com/zkat/npx/issues/146
因此,命令npm init
将初始化一个新项目并生成包含项目相关信息的package.json
文件。该命令可以在任何地方运行。当您想要创建自己的新项目时,请使用npm init
。
但是,npm install
或简称npm i
,将在现有项目目录的package.json
文件中安装与项目相关的依赖项。还可以使用npm i package_name_here
将新包安装到当前项目中。该命令必须在具有有效package.json
的现有项目目录中运行