nodemailer / mailparser

Decode mime formatted e-mails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find module 'node:buffer

wintifrosch opened this issue · comments

After loading mailparser with require('mailparser'), I get an "Uncaught Error: Cannot find module 'node:buffer'".
I tried on different servers (though all with Node.js v14.17.6.), with older versions of mailparser, and with installing buffer explicitly. The error persists.

Has anyone any tips for me, please?

$ node
Welcome to Node.js v14.17.6.
Type ".help" for more information.
> const Imap = require('imap');
undefined
> 
> const {simpleParser} = require('mailparser');
Uncaught Error: Cannot find module 'node:buffer'
Require stack:
- /var/www/lists.bq-winti.ch/node/node_modules/mailparser/node_modules/libmime/lib/libmime.js
- /var/www/lists.bq-winti.ch/node/node_modules/mailparser/lib/mail-parser.js
- /var/www/lists.bq-winti.ch/node/node_modules/mailparser/index.js
- <repl>
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/www/lists.bq-winti.ch/node/node_modules/mailparser/node_modules/libmime/lib/libmime.js',
    '/var/www/lists.bq-winti.ch/node/node_modules/mailparser/lib/mail-parser.js',
    '/var/www/lists.bq-winti.ch/node/node_modules/mailparser/index.js',
    '<repl>'
  ]
}

Problem solved.
For future visitors: According to libmime issue #23 from 14 days ago the prefix node: in all referenced dependencies must be removed.

  • ./node_modules/libmime/lib/libmime.js
  • ./node_modules/libmime/lib/charset.js
  • ./node_modules/libqp/lib/libqp.js
  • ./node_modules/libbase64/lib/libbase64.js

After those changes, mailparser worked like a charm.

For details what to replace, see the issue linked above.

This is not a good solution , " just go to the node modules and make change ". what happens when we deploy our changes to server it will create the problem there . then what will do ? I am getting this issue how can We solve it ?
I am doing mail crawling to search particular mail
image

Running against this issue too with webpack

Error: Webpack Compilation Error
Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.

Module build failed: UnhandledSchemeError: Reading from "node:stream" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.

This is not a good solution , " just go to the node modules and make change ".

Yes, @crest-daksh, I'm with you. This problem must be solved on the rpm repo, but I'm not skilled to maintain a GitHub source neither publish a new release to the npm repo. Obviously, neither are you.

That's why I re-opened this issue a couple of weeks ago: The issue is not solved.

So long, you and others may be happy to find a temporary solution at least.

What's your runtime environment ?

I'm using Cypress and it seems like it's being bundled with webpack and run in the browser which causes the issue.

"mailparser is Node.js only library, so you can't use it reliably in the front-end or bundle with WebPack. If you do need a solution to parse emails in the front-end then use PostalMime."

@Lezzio Who are you adressing with your question?

What's your runtime environment ?

This Issue #372 is about using mailparser with node.
After a require('mailparser');, the dependencies are loaded, where andris9's libmime is bundled. Loading libmime throws the error "Cannot find module 'node:buffer " discussed here.
Issue #372 will persist until nodemailer/libmime#23 is re-opened and solved.

@Lezzio Who are you adressing with your question?

What's your runtime environment ?

This Issue #372 is about using mailparser with node.

After a require('mailparser');, the dependencies are loaded, where andris9's libmime is bundled. Loading libmime throws the error "Cannot find module 'node:buffer " discussed here.

Issue #372 will persist until nodemailer/libmime#23 is re-opened and solved.

@wintifrosch Why would you use webpack for a node app ?

In my case it's because I run Cypress that I bundle my js for the browser using webpack