试图为基于反应的项目设置文档。
使用“创建-反应-应用程序”中的“my-app”和一个非常天真的*.js文件,我得到了一个错误:
C:\xampp\htdocs\my-app2\node_modules\react-styleguidist\bin\styleguidist.js
You can now view your style guide in the browser:
Local: http://localhost:6060/
On your network: http://10.100.11.165:6060/
FAIL Failed to compile
./src/src/topnav/topnav.js
SyntaxError: C:\xampp\htdocs\my-app2\src\src\topnav\topnav.js: Support for the experimental syntax 'classProperties' isn't currently enabled (8:20):
6 | */
7 | export default class Button extends React.Component {
> 8 | static propTypes = {
| ^
9 | /** Description of prop "foo". */
10 | foo: PropTypes.number,
11 | /** Description of prop "baz". */
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
@ ./node_modules/react-styleguidist/lib/index.js (./node_modules/react-styleguidist/loaders/styleguide-loader.js!./node_modules/react-styleguidist/lib/index.js) 46:30-89
@ ./node_modules/react-styleguidist/lib/index.js
@ multi ./node_modules/react-styleguidist/lib/index ./node_modules/react-styleguidist/node_modules/react-dev-utils/webpackHotDevClient.js有人知道这个错误吗?
我怀疑修复与Babel有某种关系,但是,我无法从以前的查询中解决它。
发布于 2019-01-21 14:20:36
将@babel/plugin-proposal-class-properties添加到.babelrc,将@babel/plugin-proposal-class-properties添加到package.json,错误还表明
.babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}package.json
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
...https://stackoverflow.com/questions/54291640
复制相似问题