javascriptgoogle-chrome-extensionmime-messageweb-extension

postal-mime library error "TypeError: PostalMime is not a constructor"


I'm trying to use the postal-mime JS library in a Chrome browser extension using Manifest V3. My extension spawns a service worker and I'm trying to use this library there. To import it, I tried both

const { PostalMime } = require("postal-mime");

and

import { PostalMime } from "postal-mime";

while my code looks like this:

const parser = new PostalMime();
parser.parse(result).then((email) => console.log(email));

The variable result contains a standard email message as a string that I'd like to parse. In both cases, I get the following error:

Uncaught (in promise) TypeError: PostalMime is not a constructor
    at sw.js:66:1
(anonymous) @ sw.js:66
Promise.then (async)
(anonymous) @ sw.js:61

What am I doing wrong?

Thank you for your help,

GTP


Solution

  • I ended up using the library emailjs-mime-parser. While not a real solution to the asked question and despite having fewer functionalities than postal-mime, at least I'm able to import it out of the box without thinkering with Webpack's config.