简体   繁体   English

Node.js 终端中“反应不存在”

[英]“react doesn't exist” in Node.js terminal

I got that error “react doesn't exist” when I'm trying to compile jsx using babel using this command: npx babel src/index.js --out-file=public/main.js --presets=env,react当我尝试使用以下命令使用 babel 编译 jsx 时出现错误“react doesn't exist”: npx babel src/index.js --out-file=public/main.js --presets=env,react

both dependencies env and react are configured.依赖项 env 和 react 都已配置。

{"name": "React",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"},
"keywords": [],
"author": "",
"license": "ISC"}

any ideas?有任何想法吗?

Do you add React?你添加 React 了吗?

yarn add react

or npm install reactnpm install react

maybe try add this to script in package.json也许尝试将此添加到 package.json 中的脚本

{"name": "React",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "babel src/index.js --out-file=public/main.js --presets=env,react"
},
"keywords": [],
"author": "",
"license": "ISC"}

And run command:并运行命令:

yarn dev

or要么

npm run dev

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

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