因此,我使用react创建了一个应用程序,但没有从https://facebook.github.io/react/blog/2016/07/22/create-apps-with-no-configuration.html进行配置
我安装了mobx和mobx-react,但仍然在@ symb之前显示了意外令牌的错误。
是否需要添加其他内容,或者我当前的配置是错误的?:(
package.json
"devDependencies": {
"react-scripts": "0.8.4",
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0"
},
"dependencies": {
"autobind-decorator": "^1.3.4",
"classnames": "^2.2.5",
"lodash": "^4.15.0",
"mobx": "^2.5.1",
"mobx-react": "^3.5.5",
"react": "^15.3.1",
"react-dom": "^15.3.1",
"validator": "^5.6.0"
},.babelrc
{
"presets": ["es2015", "stage-0", "react"],
"plugins": [
"transform-decorators-legacy",
"transform-class-properties"
]
}和代码
import React, { Component } from 'react';
import { action, observable } from 'mobx'
import {observer} from 'mobx-react';
class App {
@observer cake = [];
}
export default new App();发布于 2016-12-14 18:07:10
不支持装饰符(@)。您可以使用 create-react-app自己添加它,从头开始设置您自己的环境,或者使用像这样的东西作为起点。
我个人在上使用过,取得了很大的成功。
发布于 2018-01-24 06:37:28
运行npm run eject后,您缺少包(因为create-react-app不支持装饰器)。
运行npm install --save-dev babel-plugin-transform-decorators-legacy babel-plugin-transform-class-properties
然后将以下Babel配置添加到您的package.json
"babel": {
"plugins": [
"transform-decorators-legacy"
],
"presets": [
"react-app"
]
},发布于 2017-01-18 07:06:13
https://stackoverflow.com/questions/41138534
复制相似问题