Skip to content

Instantly share code, notes, and snippets.

@CodingPapi
Created July 8, 2017 07:12
Show Gist options
  • Save CodingPapi/3a37048f24953f40be227a4f8dbdc464 to your computer and use it in GitHub Desktop.
Save CodingPapi/3a37048f24953f40be227a4f8dbdc464 to your computer and use it in GitHub Desktop.
Node dynamic import modules
ES6 specification doesn't seem to support the dynamic loading of modules:
function renderView(viewName) {
const view = require(path.join('./views', viewName));
...
}
@kruncher dynamic module loads go through System
function renderView (viewName) {
System.import(path.join('./views', viewName))
.then(view => ...)
.catch(error => console.error(error.stack));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment