我正在尝试设置react-datepicker 页面上提供的代码。
我的构建工具链由 npm 和 browserify 组成。
我有以下 package.json
{
"name": "datepicker",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "browserify -o public/bundle.js -v -d main.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"babelify": "^7.0.0",
"browserify": "^12.0.1",
"browserify-css": "^0.14.0",
"react": "16.5",
"react-datepicker": "^2.0.0",
"react-dom": "^16.5",
"reactify": "^1.1.1"
},
"browserify-css": {
"autoInject": true,
"minify": true,
"rootDir": ".",
"output": "backend/public/bundle.css"
},
"browserify": {
"transform": [
"babelify",
"browserify-css"
]
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2"
}
}
我的 main.js 组成如下:
import React from "react";
import ReactDOM from "react-dom"
import DatePicker from "react-datepicker";
// CSS Modules, react-datepicker-cssmodules.css
import 'react-datepicker/dist/react-datepicker-cssmodules.css';
class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
startDate: new Date()
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(date) {
this.setState({
startDate: date
});
}
render() {
return (
<DatePicker
selected={this.state.startDate}
onChange={this.handleChange}
/>
);
}
}
ReactDOM.render(<Example />, document.getElementById('app'))
然后我跑
npm run start
我收到了这条信息
语法错误:/home/mylogin/test_react_go/datepicker/main.js:意外令牌(26:6)
我花了一些时间来理解这个问题,但还没有找到任何解决方案。如果有人更习惯于现代 js 工具可以帮助我,我会很高兴。