mailparser icon indicating copy to clipboard operation
mailparser copied to clipboard

`TypeError: simpleParser is not a function`

Open rcffc opened this issue 2 years ago • 1 comments

nodemailer version: 6.8.0

Consider following snippet from my project using ES modules:

import simpleParser from 'nodemailer';
let stream;
simpleParser(stream, (err, parsed) => {});

Running it would throw

TypeError: simpleParser is not a function
    at file:///home/taro/projects/onefleet-worktrees/dev/B/services/location/test.ts:3:1
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:526:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Then, when I look into node_modules/mailparser/index.js, I see that require imports are used.

'use strict';

const MailParser = require('./lib/mail-parser');
const simpleParser = require('./lib/simple-parser');

module.exports = {
    MailParser,
    simpleParser
};

Does that mean I cannot use your package unless I switch back to CJS or is there another way?

Cheers.

rcffc avatar Dec 12 '22 15:12 rcffc

Part of the problem is that you're importing from nodemailer instead of mailparser. Try this:

import { simpleParser } from 'mailparser';

canac avatar Jan 02 '23 17:01 canac