【发布时间】:2020-09-06 13:50:06
【问题描述】:
我正在尝试使用以下命令安装下一个 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
更多信息:https://github.com/zkat/npx/issues/146
【问题讨论】:
-
npm 我会安装包!!! npm init 会将所有模块安装到文件夹中
-
@SaadSohail 所以我做错了什么我必须做 init。
-
no no npm init 将带来所有必需的平均基本模块,但如果你想使用 express,那么你必须使用 npm i 或 npm install 来安装该模块