简体   繁体   English

错误:使用 web-pack 时缺少类属性转换

[英]Error: Missing class properties transform on class properties when using web-pack

I am using web-pack and flowtype.我正在使用 web-pack 和 flowtype。

The following code result valid in flowtype but when building the application using web-pack I receive the following error:以下代码在 flowtype 中有效,但在使用 web-pack 构建应用程序时,我收到以下错误:

ERROR in ./src/map/MapOpenLayer.js Module build failed: SyntaxError: Missing class properties transform. ./src/map/MapOpenLayer.js 模块构建失败:语法错误:缺少类属性转换。

8 | 8 | */ 9 | */ 9 | class MapOpenLayer extends React.Component { class MapOpenLayer 扩展了 React.Component {

10 | 10 | olMap: Object; olMap:对象;

I have tried to install babel-plugin-transform-class-properties我尝试安装babel-plugin-transform-class-properties

and making some settings in my .babelrc file but with no success.并在我的 .babelrc 文件中进行了一些设置,但没有成功。

I think the issue is related with web-pack.我认为这个问题与 web-pack 相关。 Could you please point me out what is wrong and how to fix it?你能指出我出了什么问题以及如何解决吗?

 class MapOpenLayer extends React.Component < any, any > { olMap: Object; state: Object; constructor(props: Object) { super(props) this.olMap = {} this.state = { activeMapRegion: 'currentLocation', activeMapType: 'temperature' } } }

My package.json我的 package.json

 "dependencies": { "babel": "6.23.0", "babel-cli": "6.24.0", "babel-preset-flow":"6.23.0", "babel-core": "6.24.0", "babel-loader": "6.4.1", "babel-plugin-recharts": "1.1.0", "babel-polyfill": "6.23.0", "babel-preset-es2015": "6.24.0", "babel-preset-react": "6.23.0", "babel-preset-stage-2": "6.24.1", "bower": "1.8.0", "css-loader": "0.28.1", "dot-prop-immutable": "1.3.1", "extract-text-webpack-plugin": "2.1.0", "file-loader": "0.11.1", "flux-standard-action": "1.2.0", "react": "15.6.1", "react-dom": "15.6.1", "react-redux": "5.0.6", "react-router": "4.1.1", "react-router-dom": "4.1.1", "recharts": "0.22.4", "redux": "3.6.0", "redux-promise-middleware": "4.2.0", "redux-thunk": "2.2.0", "moment": "2.18.1", "style-loader": "0.17.0", "openlayers": "4.1.1", "url-loader": "0.5.8", "weather-icons": "1.3.2", "webpack": "2.2.1", "webpack-dev-server": "2.4.2", "babel-plugin-transform-class-properties":"6.24.1" }, "devDependencies": { "babel-eslint": "8.0.0", "enzyme": "2.9.1", "enzyme-to-json": "1.5.1", "eslint": "4.7.0", "eslint-plugin-react": "6.10.0", "jest": "21.1.0", "jest-css-modules": "1.1.0", "jest-enzyme": "3.8.2", "react-addons-test-utils": "15.6.0", "react-test-renderer": "15.6.1", "redux-mock-store": "1.3.0", "redux-test-utils": "0.1.2", "sinon": "3.2.1", "standard": "10.0.3", "jest-cli":"21.1.0", "fetch-mock":"5.12.2", "flow-bin": "0.55.0", "flow-typed":"2.1.5", "flow-upgrade":"1.0.3", "eslint-config-standard":"10.2.1", "eslint-config-standard-flow": "1.0.1", "npx":"9.6.0", "babel-plugin-transform-class-properties":"6.24.1" },

my .babelrc我的 .babelrc

 { "presets": [ "stage-2", "es2015", "react", "flow" ], "plugins": [ "recharts", "transform-class-properties" ] }

I was able to fix this issue adding plugins information in both .babelrc and web-pack configuration:我能够在 .babelrc 和 web-pack 配置中添加插件信息来解决这个问题:

 module: { loaders: [ { test: /\\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader', query: { plugins: [ 'recharts', 'transform-flow-strip-types', 'transform-class-properties' ], presets: [ 'es2015', 'stage-0', 'stage-2' ] } } ] }

.babelrc .babelrc

 { "presets": [ "es2015", "stage-0", "stage-2", "react", "flow" ], "plugins": [ "recharts", "transform-flow-strip-types", "transform-class-properties" ] }

I think you need another babel plugin as well.我认为您还需要另一个 babel 插件。 transform-flow-strip-types.变换流带类型。

In your .babelrc在你的 .babelrc

{

 "plugins": ["transform-flow-strip-types","transform-class-properties"]
}

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

相关问题 错误:缺少 class 属性转换 - Error: Missing class properties transform ECMAScript 5 - 错误缺少类属性转换 - ECMAScript 5 - Error Missing class properties transform 缺少类属性转换反应 - Missing class properties transform react 模块构建失败:SyntaxError:使用webpack2时缺少类属性转换 - Module build failed: SyntaxError: Missing class properties transform when using webpack2 反应摩卡 - “缺少类属性转换” - React Mocha - `Missing class properties transform` web-pack 配置无效:配置具有未知属性“devserver”。 这些属性有效 - web-pack configuration is not valid: configuration has an unknown property 'devserver'. These properties are valid 无法使用带有 babel 加载器的 web-pack 编译 JSX - Unable to compile JSX using web-pack with babel loader 引入抽象 class 或属性时出现 Typescript 错误? - Typescript error when introducing Abstract class or properties? JQuery在Class中设置CSS Transform,Translate Properties - JQuery set CSS Transform, Translate Properties in Class 带有预设环境(无选项)和预设打字稿的 Babel 说“缺少 class 属性转换”。 为什么? - Babel with preset-env (no options) and preset-typescript says “Missing class properties transform”. Why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM