Clone this repo and follow the readme to see it in action.
Cause:
When webpacked, the whole compiled Elm code is evaluated within a CommonJS environment.
The marked library detects the module object and exports itself as a proper CommonJS module should. As a result, the native Markdown module loses access to a global marked function.
Fix:
Nest the marked library inside our own CommonJS-compatible environment and capture the exported object as a local variable.
var marked = (function() {
var module = {};
var exports = module.exports = {};
// insert marked library here
return module.exports;
})();
Problem:
When webpacked,
Markdown.toHtml
fails with:Clone this repo and follow the readme to see it in action.
Cause:
When webpacked, the whole compiled Elm code is evaluated within a CommonJS environment.
The
marked
library detects themodule
object and exports itself as a proper CommonJS module should. As a result, the native Markdown module loses access to a globalmarked
function.Fix:
Nest the
marked
library inside our own CommonJS-compatible environment and capture the exported object as a local variable.QA
elm-make src/Main.elm --output main.html
should work too