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 gist.github.com link you used returns the file as type text/plain. One way to fix this is to paste the gist link on raw.githack.com and use either of the resulting URL(s) instead:

https://gist.githack.com/vorth/c8f811806e5ade9341a0e588b7ba3320/raw/f840e7bdc396638d800d5706a3ae83d6b23a1e42/ZomicParser.js

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())))
2 Likes

Awesome, thank you both!