【发布时间】:2021-01-25 06:49:38
【问题描述】:
我想在我的表单中使用 react-validation 组件 Input。这就是为什么我将它导入并在表单中使用:
<Input className="form-control"
type="text"
placeholder="name"
value={props.data.creatingUser.createName}
name="createName"
id="createName"
onChange={props.handleAddChange}
required/>
当我尝试使用 npm start 运行应用程序时,我在控制台中收到以下错误:
语法错误: E:\Projects\personal\rental-application\node_modules\react-validation\src\components\input\index.js: 当前未启用对实验性语法“jsx”的支持 (6:3):
const Input = ({ error, isChanged, isUsed, ...props }) => (
| ^ <input {...props} {...( isChanged && isUsed && error ? { className: `is-invalid-input ${props.className}` } : { className: props.className } )} />
我没有明确做过任何babel配置,我的package.json文件有如下内容:
{
"name": "rental-application",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.3",
"@testing-library/user-event": "^12.6.0",
"jquery": "^3.5.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4",
"popper.js": "1.16.1",
"css-loader": "^5.0.1",
"react-bootstrap": "^1.4.3",
"sass-loader": "^10.1.1",
"style-loader": "^2.0.0",
"axios": "^0.21.1",
"react-notifications": "^1.7.2",
"react-fontawesome": "^1.7.1",
"react-table": "^6.11.4",
"react-validation": "^3.0.7"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-transform-async-to-generator": "^7.12.1",
"react-router-dom": "^5.2.0",
"react-table-6": "^6.11.0"
}
}
我的项目结构:
++node_modules
++public
+++index.html
+++manifest.json
+++robots.txt
++src
+++App.js
+++index.js
+++index.css
++package.json
++package-lock.json
你可以看到我没有使用任何其他配置,并且我已经使用 create-react-app 命令启动了项目。
【问题讨论】:
标签: reactjs babel-loader