babeljs

Why does Object.assign() require a polyfill when babel-loader is being used?

两盒软妹~` 提交于 2019-12-28 11:43:33
问题 I'm attempting to use Object.assign() in an ES6 web app compiled by Babel with webpack, but I'm getting an error: Uncaught TypeError: Object.assign is not a function I'm already using babel-loader to transpile ES6 to ES5, so all my other ES6 code is working. Yet, Object.assign() only works after I also import "babel-core/polyfill" in my codebase. I see that I can also fix this by importing babel-runtime, but I'd like to understand why Object.assign() requires more than what babel-loader

Support for the experimental syntax 'classProperties' isn't currently enabled

丶灬走出姿态 提交于 2019-12-28 05:06:06
问题 While I was setting up React within Django project I came across this error ModuleBuildError in Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: C:\Users\1Sun\Cebula3\cebula_react\assets\js\index.js: Support for the experimental syntax 'classProperties' isn't currently enabled (17:9): 15 | 16 | class BodyPartWrapper extends Component { > 17 | state = { | ^ 18 | 19 | } 20 | Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins'

Transpile Async Await proposal with Babel.js?

对着背影说爱祢 提交于 2019-12-28 02:26:06
问题 There is a proposal for introducing C# style async-await . I know Babel.js transpiles ES6 to ES5, but is there any way to make it transpile async-await to ES5 ? 回答1: Babel v6 As of Babel v6, Babel doesn't contain any transformers itself anymore. You have to explicitly specify any feature you want to transform. Presets - non ES2015 environment The quickest way to get this working is to use presets which already contain the set of plugins needed to transform ES2015 and newer proposals. For

Javascript: How to create ES5 lib with ES6

十年热恋 提交于 2019-12-25 18:35:08
问题 I'm working with GoogleAppsScript. I'm trying to have my code locally in order to: - use github - write ES6 I'm using webpack, and generating a bundle that will run in a html page is not a problem. But I don't know for now how to generate a bundle that I will be able to copy/paste to GoogleAppsScript. The main.js file that I create is something like that : import Point from './Point.js' import Test from './test.js' import SpreadSheetLogger from './SpreadSheetLogger.js' And when I look to the

Modify objects in ES6 source code by webpack/babel

不羁岁月 提交于 2019-12-25 08:46:53
问题 There is ES6-application which is bundled with webpack and babel plugins. Is it possible to modify some source code, to inject hidden field in every object? Some babel/webpack plugins, including webpack-replace-plugin and babel-minify-replace, allows to interop field accessing and create some macro-definitions But problem is wrap all object creation, and insert some field with unique name. It should be everywhere - in object creation literals, in rest-spread copy and so on, so naïve replace

Transpiling jsx using babel for react app

孤街浪徒 提交于 2019-12-25 07:15:03
问题 I am trying to transpile a jsx file using babel and its giving an error. The content of the file is as follows, ( src/app.js ) class Channel extends React.Component{ render() { return( <li> Something </li> ) } } I used the following commands to transpile and watch the file for changes. 1) babel src/app.js --watch --out-file js/app.js 2) babel src/app.js --presets es2015 --watch --out-file js/app.js In both the cases I recieved the following error, SyntaxError: src/app.js: Unexpected token (4

React-Native Install Error with Babel ES2015

為{幸葍}努か 提交于 2019-12-25 06:32:41
问题 I am trying to start a new react-native project following the Getting Started example in the projects docs. Below is the install and error I get. NODE is 5.2, NPM is 3.3.12. Mac is El Capitain. I get an error: Error: Couldn't find preset "es2015" relative to directory referencing ES2015 relative to directory. I then follow the advice here and have both presets installed globally and locally in the project. You can see it in the npm ls -g command below that its installed globally. After

How to enable support for class properties in the latest version BabelJS?

為{幸葍}努か 提交于 2019-12-25 05:55:12
问题 Does anyone know how to enable support for properties of a class in the latest version BabelJS? import React from 'react'; import {Component} from 'react'; export default class Button extends Component { constructor(){ super(); } myProp = {}; // ERROR: /path/to/file/Button.jsx: Unexpected token (9:11) render(){ return <div></div>; } } 回答1: With Babel 6, you use the syntax-class-properties plugin, by installing it: npm install babel-plugin-syntax-class-properties and adding it to your .babelrc

How to enable support for class properties in the latest version BabelJS?

蹲街弑〆低调 提交于 2019-12-25 05:55:03
问题 Does anyone know how to enable support for properties of a class in the latest version BabelJS? import React from 'react'; import {Component} from 'react'; export default class Button extends Component { constructor(){ super(); } myProp = {}; // ERROR: /path/to/file/Button.jsx: Unexpected token (9:11) render(){ return <div></div>; } } 回答1: With Babel 6, you use the syntax-class-properties plugin, by installing it: npm install babel-plugin-syntax-class-properties and adding it to your .babelrc

Spread operator not recognized by WebPack under Vue

无人久伴 提交于 2019-12-25 04:38:30
问题 In this answer the following syntax's been suggested. import { mapActions } from 'vuex' export default { vuex: { getters: { activeDataRow: state => state.activeDataRow }, actions: { updateData, resetData } }, methods: { ...mapActions(['updateData', 'resetData']) } } I can't make it work and I'm getting the error: Module build failed: SyntaxError: C:/.../navigation.vue: Unexpected token (30:8) 29 | methods: { 30 | ...mapActions(['updateData', 'resetData']) | ^ 31 | } I've tried configuring