question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No matching export in node-modules-polyfillscrypto for import createHash with latest version

See original GitHub issue

Hello. I have updated my Remix app (indies-stack) dependencies and came across this error message : No matching export in node-modules-polyfillscrypto for import createHash upon building the application or starting the development environment. Going back to version 0.7.0 of mailing and mailing-core didn’t trigger the error.

I do not use crypto in my code.

(This is my first issue, forgive me if I do not provide enough details)

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:13

github_iconTop GitHub Comments

3reactions
Varkoffcommented, Oct 1, 2022

Hi @psugihara, I have tried to recreate the issue, without success. I am using React@18.2.0 btw. I have seen a notice on the terminal specifying the peer-deps of mjml-react, and react-reconciler needed 17.0.0.

I am using mailing for my Vinylmania.fr project.

 /* mailing.config.json */
{
  "typescript": true,
  "emailsDir": "./emails",
  "outDir": "./previews_html",
  "anonymousId": "c4eb5ec8-3a15-4cd8-9254-19e19a1a652b"
}
/* emails/index.ts */
import nodemailer from "nodemailer";
import { buildSendMail } from "mailing-core";
import invariant from "tiny-invariant";

invariant(process.env.SMTP_PORT, "SMTP_PORT is not set");
const transport = nodemailer.createTransport({
  pool: true,
  host: process.env.SMTP_HOST,
  port: Number(process.env.SMTP_PORT),
  secure: true, // use TLS
  auth: {
    user: process.env.SMTP_USER,
    pass: process.env.SMTP_PASSWORD,
  },
});

// @ts-ignore
const sendVinyleMail = buildSendMail({
  transport,
  defaultFrom: `Vinylmania <${process.env.SMTP_SENDER}>`,
});

export default sendVinyleMail;
2reactions
a-hariticommented, Dec 12, 2022

I found a solution, posting here to save someone some time in the future.

This is a Remix issue not Mailing’s.

The gist of it is that Remix has the concept of server vs client bundles. When in doubt it tries to make the code work for both, that’s why it’s trying to polyfill node:crypto for the borowser.

One way to tell it that this email stuff is purely a server’s business, one should name the file [name].server.ts as per the docs: https://remix.run/docs/en/v1/pages/gotchas#server-code-in-client-bundles.

In my case, I kept all of my code the same, exept that in the emails folder I have the structure:

app/emails
├── index.ts
├── previews
├── emails
└── sendEmail.server.ts

the "server" in sendEmails.server.ts deals with the issue, and the index.ts file gives me nice imports.

// app/emails/index.ts
export { default } from "./sendEmail.server";
Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR: No matching export in "node-modules ... - GitHub
Bug description This issue comes about when trying to run remix through Cloudflare pages.
Read more >
ERROR: No matching export in "node-modules-polyfills:crypto ...
I'm finding no clue on what to do about this issue when trying to run remix through Cloudflare pages. node_modules/@algolia/client-search/dist/ ...
Read more >
Nodejs crypto in typescript file - javascript - Stack Overflow
I have created my own hash.js file that requires crypto and exports two functions that use crypto. It works ...
Read more >
Crypto | Node.js v19.3.0 Documentation
The crypto.createHash() method is used to create Hash instances. Hash objects are not to be created directly using the new keyword.
Read more >
Node.js crypto.createHash() Method - GeeksforGeeks
algorithm: It is dependent on the accessible algorithms which are favored by the version of OpenSSL on the platform. It returns string.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found