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

Cannot find module 'node:buffer #372

Open
wintifrosch opened this issue Jun 14, 2024 · 7 comments
Open

Cannot find module 'node:buffer #372

wintifrosch opened this issue Jun 14, 2024 · 7 comments

Comments

@wintifrosch
Copy link

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>'
  ]
}
@wintifrosch
Copy link
Author

wintifrosch commented Jun 20, 2024

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.

@crest-daksh
Copy link

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

@Lezzio
Copy link

Lezzio commented Jul 15, 2024

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.

@wintifrosch
Copy link
Author

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.

@Lezzio
Copy link

Lezzio commented Jul 15, 2024

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."

@wintifrosch
Copy link
Author

@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
Copy link

Lezzio commented Jul 15, 2024

@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

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

3 participants