forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.64k stars 339 forks source link

Compile errors from consolidate.js #435

Closed engelkes-finstreet closed 2 years ago

engelkes-finstreet commented 2 years ago

Hey!

For reference: I am using version 8.0.10.

I get a lot of compile errors after installing email-templates. To send emails I followed the first steps in the README.md and this is what my code looks like:

  const email = new Email({
    message: {
      from: "niftylettuce@gmail.com",
    },
    // uncomment below to send emails in development/test env:
    // send: true
    transport: {
      jsonTransport: true,
    },
  });

  email
    .send({
      template: "mars",
      message: {
        to: "elon@spacex.com",
      },
      locals: {
        name: "Elon",
      },
    })
    .then(console.log)
    .catch(console.error);

After starting my server I get the following compile errors:

> node_modules/consolidate/lib/consolidate.js:204:71: error: Could not resolve "velocityjs" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
    204 │ ...quires.velocityjs || (requires.velocityjs = require('velocityjs'));
        ╵                                                        ~~~~~~~~~~~~

  > node_modules/consolidate/lib/consolidate.js:493:43: error: Could not resolve "dustjs-linkedin" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
    493 │           engine = requires.dust = require('dustjs-linkedin');
        ╵                                            ~~~~~~~~~~~~~~~~~

  > node_modules/consolidate/lib/consolidate.js:629:59: error: Could not resolve "atpl" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
    629 │     var engine = requires.atpl || (requires.atpl = require('atpl'));

Any ideas how to fix this?

niftylettuce commented 2 years ago

Have you seen https://github.com/tj/consolidate.js/issues/334?

I finally figured it out by deleting the consolidate folder from node_modules, it then pointed to which component file was showing "import cons from "consolidate";" at the top.

engelkes-finstreet commented 2 years ago

Unfortunately this does not solve the error. After removing consolidate from my node_modules I receive the following error:

 > node_modules/email-templates/lib/index.js:15:28: error: Could not resolve "consolidate" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
    15 │ const consolidate = require('consolidate');
       ╵                             ~~~~~~~~~~~~~

which is kind of expected since email-templates uses consolidate or am I thinking wrong here?

spence-s commented 2 years ago

@engelkes-finstreet this seems like a bundler issue and not really an issue with email-templates - what are you bundling for and what bundler are you using?

engelkes-finstreet commented 2 years ago

I am using Remix and just tried it for a fresh install. They are using esbuild.

paninee commented 2 years ago

Having the same issue on 9.0.0.

adamgen commented 1 year ago

I'm having the same issue using esbuild directly.

Why are all the dependencies marked as devDependencies? They are not installed locally using yarn 3, could this be the issue?

titanism commented 1 year ago

This should be now fixed, we released consolidate v1.0.0+

titanism commented 1 year ago

Please bump to v11.1.0 of email-templates to get the fix