nest-modules / mailer

📨 A mailer module for Nest framework (node.js)
https://nest-modules.github.io/mailer/
MIT License
846 stars 177 forks source link

Error: Cannot find module 'preview-email' #1179

Open CristianAdi opened 6 months ago

CristianAdi commented 6 months ago

Describe the bug After i run the first 2 commands from @nestjs-modules/mailer to install it and i run npm run start:dev, i get this big error : "Error: Cannot find module 'preview-email' Require stack:

I checked for other error but after installation i don t see any in the terminal. Another think i figure out is about "preview-email" is missing from package-lock.json, i tryed to delete the node-module and install all, but still got the same error. And the versions of what is installed on the project are up to date: ""dependencies": { "@apollo/server": "^4.10.4", "@casl/ability": "^6.7.1", "@nestjs-modules/mailer": "^2.0.0", "@nestjs/apollo": "^12.1.0", "@nestjs/common": "^10.3.8", "@nestjs/config": "^3.2.2", "@nestjs/core": "^10.3.8", "@nestjs/graphql": "^12.1.1", "@nestjs/jwt": "^10.2.0", "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.3.8", "@nestjs/swagger": "^7.3.1", "@nestjs/throttler": "^5.1.2", "@nestjs/typeorm": "^10.0.2", "bcrypt": "^5.1.1", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", "dotenv": "^16.4.5", "graphql": "^16.8.1", "graphql-scalars": "^1.23.0", "graphql-type-json": "^0.3.2", "lodash": "^4.17.21", "mysql2": "^3.9.7", "nodemailer": "^6.9.13", "passport": "^0.7.0", "passport-jwt": "^4.0.1", "passport-local": "^1.0.0", "pg": "^8.11.5", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", "typeorm": "^0.3.20" },"

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

alwyn974 commented 6 months ago

Run a npm install preview-email it should fix the error for the moment, preview-email should be an optional dependency but for some reason it's required somewhere

CristianAdi commented 6 months ago

Ye, somehow running "npm install module preview-email" solved the problem, but now i have it installed in the package.json, hope will not cause some problems !

MikeMatrix commented 6 months ago

Ran into the same issue, from what I can see, the compiled output of the npm package that got released is identical to the previous version. I rolled back to 1.11.2 for now, since from the few things I inspected, it's the same compiled code.

EDIT: Notably the absence of the fix for #1131 and the error produced by trying to load preview-email was what caught me onto this.

juandav commented 6 months ago

Preview email is now an optional dependency.

juandav commented 6 months ago

PR https://github.com/nest-modules/mailer/pull/1173 related to improvements and fixes.

jarpoole commented 6 months ago

I'm seeing the same thing. In the compiled output for 2.0.0 I still see a top level require() for preview-email. image

I had a look through the PR you linked and I don't really see how it will fix this...

MikeMatrix commented 6 months ago

Looking at npm without having any way to test it right now, the compiled code on npm in version 2.0.2 looks at least correct.

CristianAdi commented 6 months ago

I will try with the 2.0.2 version if that error is gone ! Thanks for help guys

xxwangkaimin commented 6 months ago

Is this fixing one error that leads to another error?

alumni commented 5 months ago

Seems there's isn't an easy way to ignore optional dependencies.

IMO, all of them (template engines, preview-email) should rather be optional peer dependencies, then we'd have to explicitly install them if we needed them.

Basically pnpm install will install preview-email even though it's an optional dependency and we never use it. Same goes for mjml, whose dependencies have some security issues, so we get them even though we don't even use mjml.