babeljs

Extended Errors do not have message or stack trace

こ雲淡風輕ζ 提交于 2019-12-17 20:00:05
问题 When running this snippet through BabelJS: class FooError extends Error { constructor(message) { super(message); } } let error = new FooError('foo'); console.log(error, error.message, error.stack); it outputs {} which is not what I expect. Running error = new Error('foo'); console.log(error, error.message, error.stack); produces {} foo Error: foo at eval (eval at <anonymous> (https://babeljs.io/scripts/repl.js?t=2015-05-21T16:46:33+00:00:263:11), <anonymous>:24:9) at REPL.evaluate (https:/

Object.assign is not a function

☆樱花仙子☆ 提交于 2019-12-17 15:59:11
问题 I'm using babel with gulp and create a simple DOM library in ES6. But after running and when i'm going to use it, I got the Object.assign is not a function in chrome console. this is the gulp code gulp.task('scripts', function() { return gulp.src(src + 'js/*.js') .pipe(babel()) .pipe(concat('main.js')) .pipe(gulp.dest(dest + 'js')); }); this is the class file class DOM { constructor( selector ) { var elements = document.querySelectorAll(selector); this.length = elements.length; Object.assign

Code inside DOMContentLoaded event not working

江枫思渺然 提交于 2019-12-17 15:44:08
问题 I have used <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> </head> <body> <button type="button" id="button">Click</button> <pre id="output">Not Loading...</pre> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.17.0/babel.min.js"></script> <script type="text/babel"> document.addEventListener('DOMContentLoaded', function () { const button = document.getElementById('button'); const output = document.getElementById('output'); output.textContent = 'Loading...';

Best way to polyfill ES6 features in React app that uses create-react-app

耗尽温柔 提交于 2019-12-17 15:11:04
问题 I've been testing my React.js application on internet explorer, and to my surprise, ES6 code like Array.prototype.includes() breaks it. I'm using the creat-react-app starter kit and I thought babel was a part of this, and that it allowed me to write ES6 code. Turns out its not quite so simple. From what I can see, they've chosen NOT to include a lot of polyfill as not everyone needs it, and it slows down build times. See for example here and here. There has been an attempt to document this,

JavaScript object destructuring and aliasing

空扰寡人 提交于 2019-12-17 07:52:12
问题 Is there a way to destructure an object in JavaScript and alias the local destructured object? Something like: const env = {ENV_VAR_X, ENV_VAR_Y, ENV_VAR_Z} = process.env; ...and have env become a local constant containing those selected environment variables. (I'm aware that my example doesn't work with babel) { ENV_VAR_X: "s867c7dsj4lal7", ENV_VAR_Y: "hd73m20s-a=snf77f", ENV_VAR_Z: "production" } Is there a way to achieve this aliasing? On a side note, I'm using babel as my transpiler, then

Error: Missing class properties transform

倖福魔咒の 提交于 2019-12-17 07:15:25
问题 Error: Missing class properties transform Test.js : export class Test extends Component { constructor (props) { super(props) } static contextTypes = { router: React.PropTypes.object.isRequired } .babelrc : { "presets": ["es2015", "react", "stage-0"], "plugins": ["transform-class-properties"] } package.json : "babel-core": "^6.5.1", "babel-eslint": "^4.1.8", "babel-loader": "^6.2.2", "babel-plugin-react-transform": "^2.0.0", "babel-plugin-transform-class-properties": "^6.5.2", "babel-preset

remove console.logs with Webpack & Uglify

非 Y 不嫁゛ 提交于 2019-12-17 06:29:29
问题 I am trying to remove console.logs with Webpack's Uglify plugin but it seems that Uglify plugin that comes bundled with Webpack doesn't have that option, its not mentioned in documentation. I am initializing uglify from webpack like this: new webpack.optimize.UglifyJsPlugin() My understanding is that I can use standalone Uglify lib to get all the options, but I don't know which one? The problem is that drop_console isn't working. 回答1: With UglifyJsPlugin we can handle comments, warnings,

Extending Error in Javascript with ES6 syntax & Babel

时间秒杀一切 提交于 2019-12-17 05:34:32
问题 I am trying to extend Error with ES6 and Babel. It isn't working out. class MyError extends Error { constructor(m) { super(m); } } var error = new Error("ll"); var myerror = new MyError("ll"); console.log(error.message) //shows up correctly console.log(myerror.message) //shows empty string The Error object never get the right message set. Try in Babel REPL. Now I have seen a few solutions on SO (for example here), but they all seem very un-ES6-y. How to do it in a nice, ES6 way? (That is

Difference between import X and import * as X in node.js (ES6 / Babel)?

强颜欢笑 提交于 2019-12-17 05:05:26
问题 I have a node.js library lib written in ES6 (compiled with Babel) in which I export the following submodules: "use strict"; import * as _config from './config'; import * as _db from './db'; import * as _storage from './storage'; export var config = _config; export var db = _db; export var storage = _storage; If from my main project I include the library like this import * as lib from 'lib'; console.log(lib); I can see the proper output and it work as expected { config: ... } . However, if I

Difference between import X and import * as X in node.js (ES6 / Babel)?

丶灬走出姿态 提交于 2019-12-17 05:04:22
问题 I have a node.js library lib written in ES6 (compiled with Babel) in which I export the following submodules: "use strict"; import * as _config from './config'; import * as _db from './db'; import * as _storage from './storage'; export var config = _config; export var db = _db; export var storage = _storage; If from my main project I include the library like this import * as lib from 'lib'; console.log(lib); I can see the proper output and it work as expected { config: ... } . However, if I