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.67k stars 337 forks source link

Error: Cannot find module 'underscore' #323

Closed perry-mitchell closed 6 years ago

perry-mitchell commented 6 years ago

Seems that upon installing email-templates and pug, by importing email-templates I get the following error:

image

The code I'm using is quite simple:

const Email = require("email-templates");

const email = new Email({
    message: { from: fromAddr },
    send: true,
    transport: __transport
});
email
    .send({
        template,
        message: { to: toAddr },
        locals: Object.assign({
            emailID
        }, properties)
    });

__transport is a Nodemailer transport instance:

__transport = nodemailer.createTransport({
    SES: getSES()
});

I'm running this on Node 10 in a docker container. Everything installs fine, but I get that error when I try to run that code. I'm using Nodemailer v4.6.8 and email-templates v5.0.0.

niftylettuce commented 6 years ago

Reinstall node_modules and/or reinstall node. This does not seem to be related to this package since this package does not use underscore directly.

perry-mitchell commented 6 years ago

Ok, I can try that, but npm install is run properly each time.

Why close the issue so soon?

perry-mitchell commented 6 years ago

This does not seem to be related to this package since this package does not use underscore directly.

@niftylettuce How can you be so sure? It only occurs when I install this module, and only when I require it. Otherwise there is no error with my application. Clean install of Node 10 on Ubuntu.

perry-mitchell commented 6 years ago

I cleared everything, destroyed the container, and I still get this:

image

There seems to be some issue with this library and it's dependency. Running npm-why I get this:

image

So it is clearly a dependency of this library.

perry-mitchell commented 6 years ago

Well thanks for the overwhelming support. I'll find another library.

niftylettuce commented 6 years ago

I need a little more time to respond, I will re-open this, sorry I work full time and manage a team and then some, keeping up with open source is hard. I think what I'll do is update that dependency to a newer version of underscore or switch it to lodash and see if that fixes issue.

On Thu, Sep 20, 2018, 2:58 PM Perry Mitchell notifications@github.com wrote:

Well thanks for the overwhelming support. I'll find another library.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/323#issuecomment-423313108, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7haJ3CPQenqxeYtX4t6uo9TK5SliCks5uc_N-gaJpZM4WytYQ .

niftylettuce commented 5 years ago

Are you still getting this error? Would love to hear back. I haven't had anyone with a similar report and we've updated a few things in the project.

bonesoul commented 4 years ago

yes i can confirm it does still exists.

shaunwarman commented 4 years ago

email-templates / node / npm versions? Have a stacktrace?

bonesoul commented 4 years ago
    "node": "14.13.1",
    "npm": "6.14.8"
Error: Cannot find module 'underscore'
Require stack:
- E:\source\hypetraq\node_modules\underscore.deep\underscore.deep.js
- E:\source\hypetraq\node_modules\country-language\index.js
- E:\source\hypetraq\node_modules\@ladjs\i18n\index.js
- E:\source\hypetraq\node_modules\email-templates\lib\index.js
- E:\source\hypetraq\src\common\mail\mailer.js
- E:\source\hypetraq\src\web\controllers\frontend\page\page.js
- E:\source\hypetraq\src\web\routes\frontend\page.js
- E:\source\hypetraq\src\web\routes\frontend\frontend.js
- E:\source\hypetraq\src\web\routes\routes.js
- E:\source\hypetraq\src\web\server.js
- E:\source\hypetraq\src\web\app.js
shaunwarman commented 4 years ago

Do you by chance have underscore in your devDependencies and it's getting cleaned up?

bonesoul commented 4 years ago

nope, have been using lodash for a long time never used underscore within my projects.

niftylettuce commented 4 years ago

Your error message is about underscore.deep. This may either be due to you using underscore.deep directly in your project (separate from this package require) or it's an issue with country-language, which has underscore.deep as a dependency, which is in turn a dependency of i18n-locales. I'm guessing you're on an old version of npm, yarn, or something is cached and its not installing all the deps recursively.

bonesoul commented 4 years ago

i'm not using any of those packages you mention directly on my project.

email-templates -> "@ladjs/i18n": "^6.0.0", i18n: -> "country-language": "^0.1.7", country-language -> "underscore.deep": "~0.5.1"

niftylettuce commented 4 years ago

Nobody else seems to have this issue. Can you try rm -rf node_modules yarn.lock and also npm cache clear --force or yarn cache clean? What version of npm or yarn are you running? What version of Node? If you wipe your node_modules dir and also clear your package manager cache, then reinstall with npm install should be good.