Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: simpleParser is not a function #326

Open
rcffc opened this issue Dec 12, 2022 · 1 comment
Open

TypeError: simpleParser is not a function #326

rcffc opened this issue Dec 12, 2022 · 1 comment

Comments

@rcffc
Copy link

rcffc commented Dec 12, 2022

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 rcffc changed the title Make ES Modules import possible TypeError: simpleParser is not a function Dec 12, 2022
@canac
Copy link

canac commented Jan 2, 2023

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

import { simpleParser } from 'mailparser';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants