'Could not load email provider "nodemailer" (Strapi)

I'm trying to setup the strapi application with nodemailer.

I've added the nodemailer dependency with yarn add @strapi/provider-email-nodemailer as on the official page described. Afterwards I've added the following configuration to my plugins.js file (I've replaced sensitive informations with XXXXXXXX):

module.exports = ({ env }) => ({
    email: {
        config: {
            provider: 'nodemailer',
            providerOptions: {
                host: env('SMTP_HOST', 'XXXXXXXX'),
                port: env('SMTP_PORT', 587),
                auth: {
                    user: env('SMTP_USERNAME', 'XXXXXXXX'),
                    pass: env('SMTP_PASSWORD', 'XXXXXXXX'),
                },
                secure: true
            },
            settings: {
                defaultFrom: 'XXXXXXXX',
                defaultReplyTo: 'XXXXXXXX',
            },
        },
    },
});

But when I try to strap Strapi with yarn develop I get the following error message:

C:\Dev\Strapi\Projects\strapi>yarn develop
yarn run v1.22.15
$ strapi develop
Building your admin UI with development configuration ...
Admin UI built successfully
[2021-12-27 23:27:51.485] debug: ⛔️ Server wasn't able to start properly.
[2021-12-27 23:27:51.487] error: Could not load email provider "nodemailer".
Error: Could not load email provider "nodemailer".
    at createProvider (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\plugin-email\server\bootstrap.js:23:11)
    at Object.module.exports [as bootstrap] (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\plugin-email\server\bootstrap.js:31:37)
    at Object.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\core\domain\module\index.js:40:47)
    at Object.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\core\registries\modules.js:28:19)
    at async Strapi.runLifecyclesFunctions (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\Strapi.js:463:5)
    at async Strapi.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\Strapi.js:401:5)
    at async Strapi.load (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\Strapi.js:410:5)
    at async Strapi.start (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\Strapi.js:161:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What am I doing wrong? The configuration seems so simple so I don't have any idea what's wrong.



Solution 1:[1]

You need remove config section:

email: {
  provider: 'nodemailer',
  providerOptions: {
    host: env('SMTP_HOST', 'smtp.xxxxxx.xx'),
    port: env('SMTP_PORT', xxx),
    secure: true,
    auth: {
      user: env('SMTP_USERNAME'),
      pass: env('SMTP_PASSWORD'),
    },
  },
  settings: {
    defaultFrom: env('SMTP_FROM_EMAIL'),
    defaultReplyTo: env('SMTP_REPLY_EMAIL'),
  },
},

UPD: Sorry, I understood now that I use this package https://www.npmjs.com/package/strapi-provider-email-nodemailer and you used this https://www.npmjs.com/package/@strapi/provider-email-nodemailer

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1