简体   繁体   English

Node.js 命令提示符中的“反应不存在”

[英]"react doesn't exist" in Node.js command prompt

This is my 1st question in this site:)这是我在这个网站上的第一个问题:)

I'm pretty new to coding and I'm currently working in react.我对编码还很陌生,目前正在从事 React 工作。

I was making my first project yesterday, today I went back to it and initialized live-server and babel compiler for my jsx component, this is the code I put in:昨天我在做我的第一个项目,今天我回到它并为我的 jsx 组件初始化了 live-server 和 babel 编译器,这是我输入的代码:

C:\Users\asus\Desktop\Adolf\react-course-projects\indecision-app>babel src/playg round/play.js --out-file=public/scripts/app.js --presets=env, react --watch C:\Users\asus\Desktop\Adolf\react-course-projects\indecision-app>babel src/playg round/play.js --out-file=public/scripts/app.js --presets=env, 反应 - 手表

But after I hit enter all it answers its:但是在我点击 enter all 之后它回答了它:

"react doesn't exist" “反应不存在”

if I take "react" off the code and leave just env it works fine, but I think it must be there for correct parsing or something... i already did npm install again...如果我从代码中删除“反应”并只留下 env 它工作正常,但我认为它必须在那里进行正确的解析或其他......我已经再次安装了 npm ...

This is my package.json这是我的 package.json

 { "name": "indecision-app", "version": "1.0.0", "main": "index.js", "license": "MIT", "dependencies": { "babel-preset-env": "1.5.2", "babel-preset-react": "6.24.1" } }

Seems like both dependencies are there...似乎两个依赖项都在那里......

Any ideas?有任何想法吗?

Thanks in advance: :)提前致谢: :)

It looks like you're missinng react package.看起来你缺少反应包。

But if you're new to React, I would suggest to start with create-react-app https://github.com/facebook/create-react-app .但如果您是 React 新手,我建议您从 create-react-app https://github.com/facebook/create-react-app开始。 That will setup everything for you, it's easier to start with that.这将为您设置一切,从那开始更容易。

{
  "name": "indecision-app",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "babel-preset-env": "1.5.2",
    "babel-preset-react": "6.24.1"
    "react": "16.3.1",
    "react-dom": "16.3.1",
  }
}

you need to install react and react-dom use npm install --save react react-dom to add those on you dependencies.您需要安装 react 和 react-dom 使用 npm install --save react react-dom 来添加那些依赖项。

In this tutorial, you're supposed to cut the JSX written in public/scripts/app and pasted it in src/app.在本教程中,您应该剪切在 public/scripts/app 中编写的 JSX 并将其粘贴到 src/app 中。 Your babel command then requests that the JSX in src/app gets transpiled into the 'output file' public/scripts/app.然后,您的 babel 命令请求将 src/app 中的 JSX 转换为“输出文件”public/scripts/app。

Unless the JSX is in the right file, you'll also get the same error you described.除非 JSX 在正确的文件中,否则您也会遇到与您描述的相同的错误。

the following command should not have a space between env and react babel src/playg round/play.js --out-file=public/scripts/app.js --presets=env, react --watch以下命令在 env 和 react babel src/playg round/play.js --out-file=public/scripts/app.js --presets=env, react --watch 之间不应有空格

try this babel src/playg round/play.js --out-file=public/scripts/app.js --presets=env,react --watch试试这个 babel src/playg round/play.js --out-file=public/scripts/app.js --presets=env,react --watch

it should work它应该工作

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

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