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

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

Open
CristianAdi opened this issue Apr 30, 2024 · 10 comments
Open

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

CristianAdi opened this issue Apr 30, 2024 · 10 comments

Comments

@CristianAdi
Copy link

CristianAdi commented Apr 30, 2024

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:

  • /home/cristi/Documents/work/employee-record/node_modules/@nestjs-modules/mailer/dist/mailer.service.js
  • /home/cristi/Documents/work/employee-record/node_modules/@nestjs-modules/mailer/dist/mailer-core.module.js
  • /home/cristi/Documents/work/employee-record/node_modules/@nestjs-modules/mailer/dist/mailer.module.js
  • /home/cristi/Documents/work/employee-record/node_modules/@nestjs-modules/mailer/dist/index.js
  • /home/cristi/Documents/work/employee-record/node_modules/@nestjs-modules/mailer/index.js
  • /home/cristi/Documents/work/employee-record/dist/features/authentication/user/mail-verification.service.js
  • /home/cristi/Documents/work/employee-record/dist/features/authentication/user/user.service.js
  • /home/cristi/Documents/work/employee-record/dist/features/authentication/user/resolvers/user-mutation.resolver.js
  • /home/cristi/Documents/work/employee-record/dist/features/authentication/user/user.module.js
  • /home/cristi/Documents/work/employee-record/dist/app.module.js
  • /home/cristi/Documents/work/employee-record/dist/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1142:15)
    at Function.Module._load (node:internal/modules/cjs/loader:983:27)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at Object. (/home/cristi/Documents/work/employee-record/node_modules/@nestjs-modules/mailer/dist/mailer.service.js:8:22)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1021:12)
    at Module.require (node:internal/modules/cjs/loader:1230:19)"

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):

  • Ubuntu
  • Version 22.04

Additional context
Add any other context about the problem here.

@alwyn974
Copy link

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
Copy link
Author

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
Copy link

MikeMatrix commented Apr 30, 2024

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
Copy link
Member

juandav commented Apr 30, 2024

Preview email is now an optional dependency.

@juandav
Copy link
Member

juandav commented Apr 30, 2024

PR #1173 related to improvements and fixes.

@jarpoole
Copy link

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
Copy link

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
Copy link
Author

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

@xxwangkaimin
Copy link

Is this fixing one error that leads to another error?

@alumni
Copy link

alumni commented May 24, 2024

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.

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

7 participants