yads / nodemailer-express-handlebars

A plugin for nodemailer that uses express-handlebars view engine to generate emails
86 stars 29 forks source link

Not working with latest version of express-handlebars v8.0 #72

Closed ptdev closed 1 day ago

ptdev commented 1 month ago

Hi, this module stopped working when express-handlebars updated to v8 recently.

The error we got while using it (in nuxt) was:

[worker reload] [worker init] require() of ES Module /.../node_modules/express-handlebars/dist/index.js from /.../node_modules/nodemailer-express-handlebars/lib/generator.js not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /.../node_modules/express-handlebars/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

  index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
  Instead either rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in node_modules/express-handlebars/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

  at Object.<anonymous> (node_modules/nodemailer-express-handlebars/lib/generator.js:4:20)

We're using the following workaround on our package.json (when using yarn):

"resolutions": {
        "express-handlebars": "7.1.3"
 }

Cheers 👍

CloudMeshSolutions commented 1 month ago

I am facing the same issue.

rashid-citrusbits commented 1 month ago

I am facing the same issue.

natlibfi-jonollil commented 1 month ago

I am facing the same issue.

yads commented 1 day ago

I just published version 7 which should be compatible with express-handlebars@8

Zerebokep commented 1 day ago

@yads Thank you for taking care. I've upgraded to the newest version and ran in the following error now:

TypeError: Cannot read properties of undefined (reading 'create')
    at new TemplateGenerator (/node_modules/.pnpm/nodemailer-express-handlebars@7.0.0_express-handlebars@8.0.1_nodemailer@6.9.15/node_modules/nodemailer-express-handlebars/lib/generator.js:8:31)
    at default (/node_modules/.pnpm/nodemailer-express-handlebars@7.0.0_express-handlebars@8.0.1_nodemailer@6.9.15/node_modules/nodemailer-express-handlebars/lib/index.js:4:21)

Any idea?

yads commented 1 day ago

I'm not really sure, it appears there's an issue importing express-handlebars. import handlebars from 'express-handlebars'; seems to be undefined.