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

Replace 'node:buffer' with 'buffer' #23

Closed
sirgalahadcm opened this issue Jun 7, 2024 · 5 comments
Closed

Replace 'node:buffer' with 'buffer' #23

sirgalahadcm opened this issue Jun 7, 2024 · 5 comments

Comments

@sirgalahadcm
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

ENOENT: no such file or directory, open 'node:buffer'

      3 | import { uniq } from 'lodash';
      4 | import { QueryTypes } from 'sequelize';
    > 5 | import Email from 'email-templates';
        | ^
      6 | import * as path from 'path';
      7 | import { sequelize } from '../../models';
      8 | import { auditLogger, logger } from '../../logger';

      at Runtime.readFile (node_modules/jest-runtime/build/index.js:1987:21)
      at Object.<anonymous> (node_modules/libmime/lib/libmime.js:4:20)
      at Object.<anonymous> (node_modules/mailparser/lib/mail-parser.js:4:17)
      at Object.<anonymous> (node_modules/mailparser/index.js:3:20)
      at Object.<anonymous> (node_modules/preview-email/index.js:18:26)
      at Object.<anonymous> (node_modules/email-templates/src/index.js:14:22)
      at Object.<anonymous> (src/lib/mailer/index.js:5:1)
      at Object.<anonymous> (src/lib/cron.js:3:1)
      at Object.<anonymous> (src/app.js:18:1)
      at Object.<anonymous> (src/index.test.js:2:1)

Here is the diff that solved my problem:

diff --git a/node_modules/libmime/lib/charset.js b/node_modules/libmime/lib/charset.js
index 2f5686d..2ebf1d8 100644
--- a/node_modules/libmime/lib/charset.js
+++ b/node_modules/libmime/lib/charset.js
@@ -1,6 +1,6 @@
 'use strict';
 
-const { Buffer } = require('node:buffer');
+const { Buffer } = require('buffer');
 const iconv = require('iconv-lite');
 const encodingJapanese = require('encoding-japanese');
 const charsets = require('./charsets');
diff --git a/node_modules/libmime/lib/libmime.js b/node_modules/libmime/lib/libmime.js
index cfd5cb0..011bde0 100644
--- a/node_modules/libmime/lib/libmime.js
+++ b/node_modules/libmime/lib/libmime.js
@@ -1,7 +1,7 @@
 /* eslint no-control-regex: 0, no-div-regex: 0, quotes: 0 */
 'use strict';
 
-const { Buffer } = require('node:buffer');
+const { Buffer } = require('buffer');
 const libcharset = require('./charset');
 const libbase64 = require('libbase64');
 const libqp = require('libqp');

This issue body was partially generated by patch-package.

@andris9
Copy link
Member

andris9 commented Jun 7, 2024

Which nodejs version are you using? The node: prefix has been a standard for years by now. There is nothing to fix.

@andris9 andris9 closed this as completed Jun 7, 2024
@sirgalahadcm
Copy link
Author

I am trying to switch from 18 to 20 and this issue came up, but I think now it might be a config issue on my end. All uses of node:something are failing

@Lezzio
Copy link

Lezzio commented Jul 15, 2024

Hi @andris9 , it seems like webpack has issues with this syntax:
webpack/webpack#12792

Or do you think it comes from a misconfiguration on our end ?

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.
    at Watching.handle [as handler] (/Users/e0565787/Library/Caches/Cypress/13.13.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:212:23)

@Lezzio
Copy link

Lezzio commented Jul 15, 2024

You actually documented it:
"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."

The error comes with my Cypress execution, I'll dig more into it thanks!

@wintifrosch
Copy link

wintifrosch commented Jul 15, 2024

@andris9 may I ask you to re-open this issue #23 and make the changes in libmime, even though you wrote

The node: prefix has been a standard for years by now. There is nothing to fix.

There still is an issue #23 in libmime and in nodemailer/mailparser#372 as long as the "node:"-prefix is not processed as expected when libmime is required by Node.

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

4 participants