简体   繁体   English

npx create-react-app myapp 命令抛出错误

[英]npx create-react-app myapp command throwning error

I wanted to create an app in react .我想在 react 中创建一个应用程序。 I have installed the latest Node js when I am running the command I am getting error我在运行命令时安装了最新的 Node js 我收到错误

下面的错误来了。

PS C:\\Users\\Kumar Sanket\\Desktop\\React&Redux> npx create-react-app myapp Error: EEXIST: file already exists, mkdir 'C:\\Users\\Kumar' TypeError: Cannot read property 'get' of undefined at errorHandler (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\utils\\error-handler.js:205:18) at C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js:78:20 at cb (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\npm.js:228:22) at C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\npm.js:266:24 at C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\config\\core.js:83:7 at Array.forEach () at C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\config\\core.js:82:13 at f (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\once\\once.js:25:25) at afterExtras (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\config\\core.js:173:20) at C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\mkdirp\\index.js:47:53 C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\utils\\error-handler.js:205 if (npm.config.get('json')) { ^ PS C:\\Users\\Kumar Sanket\\Desktop\\React&Redux> npx create-react-app myapp 错误:EEXIST:文件已经存在,mkdir 'C:\\Users\\Kumar' TypeError:无法读取 errorHandler 处未定义的属性“get”( C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\utils\\error-handler.js:205:18) 在 C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js:78:20在 cb (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\npm.js:228:22) 在 C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\npm.js:266:24 在 C: \\Program Files\\nodejs\\node_modules\\npm\\lib\\config\\core.js:83:7 at Array.forEach () at C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\config\\core.js:82: 13 在 f (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\once\\once.js:25:25) at afterExtras (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\config\\core.js :173:20) 在 C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\mkdirp\\index.js:47:53 C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\utils\\error-handler.js :205 如果 (npm.config.get('json')) { ^

TypeError: Cannot read property 'get' of undefined at process.errorHandler (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\utils\\error-handler.js:205:18) at process.emit (events.js:189:13) at process._fatalException (internal/bootstrap/node.js:496:27) Install for create-react-app@latest failed with c类型错误:无法读取 process.errorHandler (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\utils\\error-handler.js:205:18) at process.emit (events.js: 189:13) 在 process._fatalException (internal/bootstrap/node.js:496:27) 安装 create-react-app@latest 失败,c

Today I encountered a similar issue with npx create-react-app my-app (mkdir failed).今天我在npx create-react-app my-app (mkdir failed) 中遇到了类似的问题。

Reason for my error我的错误的原因

  1. I had space in my user name folder(ex: Abc Xyz) and thus "npx" couldn't refer to it correctly (It only read Abc, and not Xyz).我的用户名文件夹中有空间(例如:Abc Xyz),因此“npx”无法正确引用它(它只读取 Abc,而不读取 Xyz)。

  2. I am using VS Code for React, and it didn't had the permission to create new directory我正在使用 VS Code for React,但它没有创建新目录的权限

How I fixed it我是如何修复它的

  1. Opened VS Code with Administrator rights.(fixed permission issue)以管理员权限打开 VS Code。(修复权限问题)

  2. Instead of using "npx" I tried the following:我没有使用“npx”,而是尝试了以下操作:

    --> npm install -g create-react-app --> npm install -g create-react-app

    --> create-react-app my-app --> create-react-app my-app

And that got executed successfully.然后就成功执行了。

Hope this helps.希望这可以帮助。

The problem is the space in the username.问题是用户名中的空格。 I use Windows 10 and I solved it by changing the path of npm cache folder in this way:我使用 Windows 10,我通过以这种方式更改 npm 缓存文件夹的路径来解决它:

  1. run npm config get cache to check the value of property cache in your config file运行npm config get cache检查配置文件中的属性缓存值
  2. if path contains a white space, you can replace the string after the space with '~1', eg I have C:\\Users\\Andrea R\\AppData\\Roaming\\npm-cache如果路径包含空格,您可以用“~1”替换空格后的字符串,例如我有C:\\Users\\Andrea R\\AppData\\Roaming\\npm-cache
  3. therefore run npm config set cache 'C:\\Users\\Andrea~1\\AppData\\Roaming\\npm-cache'因此运行npm config set cache 'C:\\Users\\Andrea~1\\AppData\\Roaming\\npm-cache'

github 上有问题,所以真的不知道该告诉你什么,但尝试安装旧版本的 CRA 链接: github.com/facebook/create-react-app/issues/6512

I have tried it several times but was not successful .我已经尝试了几次,但没有成功。 The main reason behind this was my username in the system was "Kumar Sanket" and it was not able to read anything after space.这背后的主要原因是我在系统中的用户名是“Kumar Sanket”,它在空格后无法读取任何内容。 when I changed my username i was able to run the commands.当我更改用户名时,我能够运行命令。 Thanks all for support Kumar Sanket感谢大家支持 Kumar Sanket

Install create-react-app using npm install -g create-react-app使用 npm install -g create-react-app 安装 create-react-app

then use create-react-app my-app然后使用 create-react-app my-app

no npm or npx before create-react app.在创建反应应用程序之前没有 npm 或 npx。

This EEXIST error happens due to path to node-cache directory contains a whitespace.由于节点缓存目录的路径包含空格,因此会发生此 EEXIST 错误。
Steps worked for me:步骤对我有用:

  1. create a directory manually named node-cache where path does not have any whitespace.创建一个手动命名为node-cache的目录,其中路径没有任何空格。
  2. install node cache content using command npm install --cache path/to/node-cache使用命令npm install --cache path/to/node-cache安装节点缓存内容
  3. set the new node-cache dir using command npm config set cache path/to/node-cache使用命令npm config set cache path/to/node-cache设置新的节点缓存目录
  4. now run npx create-react-app my-app现在运行npx create-react-app my-app

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

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