Can’t import() a file attachment

I updated one of my notebooks to use a file attachment to store a dependency since was down for a while. I managed to get the required JS file and make it a File Attachment. Initially, importing it worked:

parseColor = import(await FileAttachment("parse-color.js").url()).then(
  m => m.default

However, upon reloading the page, the attachment was fetched from the server with a MIME type of application/octet-stream, leading to this error:

parseColor = TypeError: 'application/octet-stream' is not a valid JavaScript MIME type.

Would it be possible to fix this or should I use another place to host the JS file?

require works, so that’s a workaround for now.

Here’s an example notebook using both import and require:

Right, we aren’t currently setting the correct MIME type to support this use case. I’m not aware of a simple workaround, unfortunately, though perhaps something like shimport would work? I’ll see if we can do a better job with MIME type detection here.

1 Like

Hi Jed,

We’ve pushed an update that should greatly improve our MIME type detection. If you upload a fresh copy of your .js file, everything should worth smoothly now.

For example: