papnkukn / eml-format

RFC 822 EML file format parser and builder
MIT License
84 stars 51 forks source link

Can't resolve 'fs' in '.../node_modlues/eml-format/lib' #8

Closed barrymichaeldoyle closed 4 years ago

barrymichaeldoyle commented 5 years ago

After added this mailparser package to my project I get the following error:

Error: Can't resolve 'fs' in '{projectPath}/node_modules/html-to-text/lib'

I've been trying various fixes but one fix just leads to another. How do I get around this issue?

pl12133 commented 5 years ago

Due to the dependency on fs, this module is not isomorphic; it cannot be run in a browser.

The parse function can be run in the browser because it doesn't depend on fs, but you need to modify the module yourself:

  1. Create a local copy of eml-format.js.
  2. Remove the function that depends on fs: emlformat.unpack.
  3. Import your local copy of eml-format.js instead of this module.

It would be nice if the underlying parser was exposed as it's own module without the fs dependency.

papnkukn commented 4 years ago

@pl12133 thanks for providing the answer.

The fs dependency has been moved inside the unpack function. Thus, the parse and other functions should now be available when running the script in a browser.

Updated with version 0.6.0.