How to use code from script with type=module [duplicate]

In a module context, variables don’t automatically get declared globally. You’ll have to attach them to window yourself. This is to prevent the scope ambiguity issues that you’d run into when using normal script tags. The import/export usage is incorrect. If you export function xyz, you must import { xyz } If you export default … Read more

Difference between ‘export’ and ‘export default’ in JavaScript? [duplicate]

It’s easiest to just look at what the three different ES6 import/export styles compile down to in CommonJS. // Three different export styles export foo; export default foo; export = foo; // The three matching import styles import {foo} from ‘blah’; import foo from ‘blah’; import * as foo from ‘blah’; Roughly compiles to: exports.foo … Read more

ES6 Destructuring and Module imports

import {Link} from ‘react-router’; imports a named export from react-router, i.e. something like export const Link = 42; import Router from ‘react-router’; const {Link} = Router; pulls out the property Link from the default export, assuming it is an object, e.g. export default { Link: 42 }; (the default export is actually nothing but a … Read more

Why doesn’t instanceof work on instances of Error subclasses under babel-node?

tl;dr If you’re on Babel 6, you can use https://www.npmjs.com/package/babel-plugin-transform-builtin-extend Extending builtin types like Array and Error and such has never been supported in Babel. It is perfectly valid in a real ES6 environment, but there are requirements to make it work that are very difficult to transpile in a way that is compatible with … Read more