Problem requiring an external AMD module.

I’m having an odd problem with require() and an external JavaScript module. (I added the AMD details so it would load as a module.) When loaded from a local file picker, the module is fine. When the exact same JavaScript is loaded from a Gist, the module is invalid.

Here is the notebook demonstrating the problem, with more details in the text content.

Thanks in advance!

You’re getting an error because the link you used returns the file as type text/plain. One way to fix this is to paste the gist link on and use either of the resulting URL(s) instead:

1 Like

Yep, what @bgchen said! GitHub doesn’t let you serve JavaScript files from Gists, I believe for security reasons. In addition to using something like GitHack to serve files from Gists, you can also jump through this hoop by fetching the file and using URL.createObjectURL:

parserModule = require.alias({
  "antlr4": antlr4,
  "ZomicParserListener": ZomicParserListener
})(URL.createObjectURL(await fetch(badURL).then(response => response.blob())))

Awesome, thank you both!