How do you JSON.stringify an ES6 Map?

Both JSON.stringify and JSON.parse support a second argument. replacer and reviver respectively. With replacer and reviver below it’s possible to add support for native Map object, including deeply nested values function replacer(key, value) { if(value instanceof Map) { return { dataType: ‘Map’, value: Array.from(value.entries()), // or with spread: value: […value] }; } else { return … Read more

Node.js plans to support import/export ES6 (ECMAScript 2015) modules

Node.js 13.2.0 & Above Node.js 13.2.0 now supports ES Modules without a flag 🎉. However, the implementation is still marked as experimental so use in production with caution. To enable ECMAScript module (ESM) support in 13.2.0, add the following to your package.json: { “type”: “module” } All .js, .mjs (or files without an extension) will … Read more

ReactJS giving error Uncaught TypeError: Super expression must either be null or a function, not undefined

Class Names Firstly, if you’re certain that you’re extending from the correctly named class, e.g. React.Component, not React.component or React.createComponent, you may need to upgrade your React version. See answers below for more information on the classes to extend from. Upgrade React React has only supported ES6-style classes since version 0.13.0 (see their official blog … Read more

eslint: error Parsing error: The keyword ‘const’ is reserved

ESLint defaults to ES5 syntax-checking. You’ll want to override to the latest well-supported version of JavaScript. Try adding a .eslintrc.json file to your project. Inside it: { “parserOptions”: { “ecmaVersion”: “latest” }, “env”: { “es6”: true } } Hopefully this helps. EDIT: I also found this example .eslintrc.json which might help.

How can I conditionally import an ES6 module?

We do have dynamic imports proposal now with ECMA. This is in stage 3. This is also available as babel-preset. Following is way to do conditional rendering as per your case. if (condition) { import(‘something’) .then((something) => { console.log(something.something); }); } This basically returns a promise. Resolution of promise is expected to have the module. … Read more

How to export imported object in ES6?

I often do the following in index.js files that compose several files: export {default as SomeClass} from ‘./SomeClass’; export {someFunction} from ‘./utils’; export {default as React} from ‘react’; This blog entry provides some nice additional examples. Important note You should be aware this eslint-rule when accessing these exported imports. Basically, in another file, you shouldn’t: … Read more