babel-loader jsx SyntaxError: Unexpected token [duplicate]

Add “babel-preset-react” npm install babel-preset-react and add “presets” option to babel-loader in your webpack.config.js (or you can add it to your .babelrc or package.js: http://babeljs.io/docs/usage/babelrc/) Here is an example webpack.config.js: { test: /\.jsx?$/, // Match both .js and .jsx files exclude: /node_modules/, loader: “babel”, query: { presets:[‘react’] } } Recently Babel 6 was released and … Read more

Call async/await functions in parallel

You can await on Promise.all(): await Promise.all([someCall(), anotherCall()]); To store the results: let [someResult, anotherResult] = await Promise.all([someCall(), anotherCall()]); Note that Promise.all fails fast, which means that as soon as one of the promises supplied to it rejects, then the entire thing rejects. const happy = (v, ms) => new Promise((resolve) => setTimeout(() => resolve(v), … Read more

Babel 6 regeneratorRuntime is not defined

babel-polyfill (deprecated as of Babel 7.4) is required. You must also install it in order to get async/await working. npm i -D babel-core babel-polyfill babel-preset-es2015 babel-preset-stage-0 babel-loader package.json “devDependencies”: { “babel-core”: “^6.0.20”, “babel-polyfill”: “^6.0.16”, “babel-preset-es2015”: “^6.0.15”, “babel-preset-stage-0”: “^6.0.15” } .babelrc { “presets”: [ “es2015”, “stage-0” ] } .js with async/await (sample code) “use strict”; export … Read more

Null-safe property access (and conditional assignment) in ES6/2015

Update (2022-01-13): Seems people are still finding this, here’s the current story: Optional Chaining is in the specification now (ES2020) and supported by all modern browsers, more in the archived proposal: https://github.com/tc39/proposal-optional-chaining babel-preset-env: If you need to support older environments that don’t have it, this is probably what you want https://babeljs.io/docs/en/babel-preset-env Babel v7 Plugin: https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining … Read more

Unable to access React instance (this) inside event handler [duplicate]

this.changeContent needs to be bound to the component instance via this.changeContent.bind(this) before being passed as the onChange prop, otherwise the this variable in the body of the function will not refer to the component instance but to window. See Function::bind. When using React.createClass instead of ES6 classes, every non-lifecycle method defined on a component is … Read more