Wildcard or asterisk (*) vs named or selective import es6 javascript

If you use webpack with the dead code elimination provided by the new uglify, or rollupjs with tree-shaking, then the unused imports will be stripped. I partially agree with the airbnb styleguide to not to use wildcard imports, although javascripts wildcard imports do not suffer from the same diseases as for example pythons or javas … Read more

What’s the purpose of the HTML “nomodule” attribute for script elements if the default is text/javascript?

The purpose of the nomodule attribute is to cause newer browsers that support module scripts to ignore a particular script element: The nomodule attribute is a boolean attribute that prevents a script from being executed in user agents that support module scripts. The spec has a good example: This example shows how to include a … 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

ES2015 “import” not working in node v6.0.0 with with –harmony_modules option

They’re just not implemented yet. Node 6.0.0 uses a version of V8 with most of ES6 features completed. Unfortunately modules isn’t one of those completed features. node –v8-options | grep harmony in progress harmony flags are not fully implemented and usually are not working: –es_staging (enable test-worthy harmony features (for internal use only)) –harmony (enable … Read more

How can I unit test non-exported functions?

Export an “exportedForTesting” const function shouldntBeExportedFn(){ // Does stuff that needs to be tested // but is not for use outside of this package } export function exportedFn(){ // A function that should be called // from code outside of this package and // uses other functions in this package } export const exportedForTesting = … Read more

Destructuring a default export object

Can I destructure a default export object on import? No. You can only destructure an object after importing it into a variable. Notice that imports/exports have syntax and semantics that are completely different from those of object literals / object patterns. The only common thing is that both use curly braces, and their shorthand representations … Read more

ES6 modules in the browser: Uncaught SyntaxError: Unexpected token import

Many modern browsers now support ES6 modules. As long as you import your scripts (including the entrypoint to your application) using <script type=”module” src=”https://stackoverflow.com/questions/41722621/…”> it will work. Take a look at caniuse.com for more details: https://caniuse.com/#feat=es6-module

What does “… resolves to a non-module entity and cannot be imported using this construct” mean?

Why it doesn’t work import * as MC from ‘./MyClass’; This is ES6/ES2015-style import syntax. The exact meaning of this is “Take the module namespace object loaded from ./MyClass and use it locally as MC“. Notably, the “module namespace object” consists only of a plain object with properties. An ES6 module object cannot be invoked … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)