如何为 npx 命令授予 mkdir 权限
Posted
技术标签:
【中文标题】如何为 npx 命令授予 mkdir 权限【英文标题】:How to give mkdir permission for npx command 【发布时间】:2021-04-16 13:02:39 【问题描述】:我在使用npx create-react-app
命令时遇到问题
早些时候,我在系统上全局安装了create-react-app
,并使用了npm create-react-app
命令
但我了解到,使用 npx 我们将始终使用最新版本,并且要使用 npx,我已经从我的系统中卸载了 create-react-app
每当我尝试运行npx create-react-app my-app
命令时
我收到以下错误:
C:\Users\Sachin Verma\Desktop\react-project>npx create-react-app tut
Error: EPERM: operation not permitted, mkdir 'C:\Users\Sachin'
command not found: create-react-app
但是如果我在我的系统上全局安装 create-react-app,那么 npx
命令可以工作
我尝试清理 npm 缓存并重新安装 node.js,但问题仍然存在
编辑: 以管理员权限运行 CMD 时
Microsoft Windows [Version 10.0.19042.685]
(c) 2020 Microsoft Corporation. All rights reserved.
C:\WINDOWS\system32>cd C:\Users\Sachin Verma\Desktop\react-project\
C:\Users\Sachin Verma\Desktop\react-project>npx create-react-app tutt
npm ERR! code ENOLOCAL
npm ERR! Could not install from "Verma\AppData\Roaming\npm-cache\_npx\14832" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sachin Verma\AppData\Roaming\npm-cache\_logs\2021-01-11T15_27_28_701Z-debug.log
Install for [ 'create-react-app@latest' ] failed with code 1
日志文件内容:
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:\\Users\\Sachin Verma\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli 'create-react-app@latest',
1 verbose cli '--global',
1 verbose cli '--prefix',
1 verbose cli 'C:\\Users\\Sachin',
1 verbose cli 'Verma\\AppData\\Roaming\\npm-cache\\_npx\\14832',
1 verbose cli '--loglevel',
1 verbose cli 'error',
1 verbose cli '--json'
1 verbose cli ]
2 info using npm@6.14.11
3 info using node@v15.5.1
4 verbose npm-session 5f8e13bb496752c5
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for file:Verma\AppData\Roaming\npm-cache\_npx\14832 Could not install from "Verma\AppData\Roaming\npm-cache\_npx\14832" as it does not contain a package.json file.
8 http fetch GET 304 https://registry.npmjs.org/create-react-app 2907ms (from cache)
9 silly pacote tag manifest for create-react-app@latest fetched in 2943ms
10 timing stage:rollbackFailedOptional Completed in 2ms
11 timing stage:runTopLevelLifecycles Completed in 2957ms
12 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\Sachin Verma\Desktop\react-project\Verma\AppData\Roaming\npm-cache\_npx\14832\package.json'
13 verbose cwd C:\Users\Sachin Verma\Desktop\react-project
14 verbose Windows_NT 10.0.19042
15 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Sachin Verma\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "create-react-app@latest" "--global" "--prefix" "C:\\Users\\Sachin" "Verma\\AppData\\Roaming\\npm-cache\\_npx\\14832" "--loglevel" "error" "--json"
16 verbose node v15.5.1
17 verbose npm v6.14.11
18 error code ENOLOCAL
19 error Could not install from "Verma\AppData\Roaming\npm-cache\_npx\14832" as it does not contain a package.json file.
20 verbose exit [ 1, true ]
由于我的用户名之间包含空格,是否有任何问题?
【问题讨论】:
可能重复:***.com/questions/54319909/… 【参考方案1】:尝试在管理中运行您的 CMD,或者您可以更改您的工作目录,不需要管理员权限。
【讨论】:
以上是关于如何为 npx 命令授予 mkdir 权限的主要内容,如果未能解决你的问题,请参考以下文章