# Must use import to load ES Module

**URL:** <https://community.auth0.com/t/must-use-import-to-load-es-module/76027>\
**Category:** Get Help\
**Created:** [January 8, 2022, 1:32am UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027 "2022-01-08T01:32:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jphillips](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jphillips/32/33480_2.png) [@jphillips](https://community.auth0.com/u/jphillips)\
**Post date:** [January 8, 2022, 1:32am UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/1 "2022-01-08T01:32:30Z")

</div>

I am attempting to use the Slack example found here [Post User Registration Flow](https://auth0.com/docs/customize/actions/triggers/post-user-registration) for a post registration Action. However, when I use the exact code I get “Must use import to load ES Module” error from Node.JS. When I follow the error instructions and use import I get “Cannot use import statement outside a module”. So I fell back to using the new dynamic import method `await import('slack-notify')` but that results in “no callback provided in dynamic import”. Has anyone seen this type of error? I triple checked my module and secrets configuration.

This is using Node16 for a post-registration Action.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 10, 2022, 3:08pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/3 "2022-01-10T15:08:59Z")

</div>

Hi @jphillips,

Thanks for reaching out.

I am running into the same error. Can you try switching to the [@slack/webhook - npm](https://www.npmjs.com/package/@slack/webhook) library?

Something like this:

```javascript
/**
 * @param {Event} event - Details about newly created user.
 */

exports.onExecutePostUserRegistration = async (event) => {
  const { IncomingWebhook } = require('@slack/webhook');
  const url = event.secrets.SLACK_WEBHOOK_URL;

  const webhook = new IncomingWebhook(url);

  // Send the notification
  (async () => {
    await webhook.send({
      text: 'I\'ve got news for you...',
    });
  })();

};

```

---

<div class="post-metadata">

**Author:** ![jphillips](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jphillips/32/33480_2.png) [@jphillips](https://community.auth0.com/u/jphillips)\
**Post date:** [January 10, 2022, 10:00pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/4 "2022-01-10T22:00:16Z")

</div>

> [@dan.woda](#):
>
> ```auto
> const { IncomingWebhook } = require('@slack/webhook');
> const url = event.secrets.SLACK_WEBHOOK_URL;
> 
> const webhook = new IncomingWebhook(url);
> 
> // Send the notification
> (async () => {
> await webhook.send({
> text: 'I\'ve got news for you...',
> });
> })();
> 
> ```

This worked, thanks so much for the solution!

---

<div class="post-metadata">

**Author:** ![admin58](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/admin58/32/33201_2.png) [@admin58](https://community.auth0.com/u/admin58)\
**Post date:** [January 11, 2022, 9:09am UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/5 "2022-01-11T09:09:06Z")

</div>

Now how can I pass the channel name using slack webhook?

The documentation on Auth0 shows the way to use require(‘slack-notify’)… but when we add slack-notify in modules, it fails and gives the “Must use import to load ES Module” error.

const slack = require(‘slack-notify’)(event.secrets.SLACK\_WEBHOOK\_URL);

```
let referrer_path = '';

const message = `New User: ${event.user.email} Came from ${JSON.stringify(api)} with the following ${JSON.stringify(event.request)} and the entire event contains ${JSON.stringify(event)}`;

const channel = '#marcoms';

slack.success({

 text: message,

 channel: channel

});

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 11, 2022, 1:09pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/6 "2022-01-11T13:09:02Z")

</div>

I don’t see that as an option in the `slack/webhook` library. If this is something you need, can you please elaborate on the use case?

---

<div class="post-metadata">

**Author:** ![jphillips](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jphillips/32/33480_2.png) [@jphillips](https://community.auth0.com/u/jphillips)\
**Post date:** [January 11, 2022, 5:22pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/8 "2022-01-11T17:22:52Z")

</div>

> [@dan.woda](#):
>
> ```auto
> const { IncomingWebhook } = require('@slack/webhook');
> const url = event.secrets.SLACK_WEBHOOK_URL;
> 
> const webhook = new IncomingWebhook(url);
> 
> // Send the notification
> (async () => {
> await webhook.send({
> text: 'I\'ve got news for you...',
> });
> })();
> 
> ```

The solution you are looking for is below, I needed to specify a channel as well so I had to poke around the code a bit.

````auto
` ```
const { IncomingWebhook } = require('@slack/webhook');
  const url = event.secrets.SLACK_WEBHOOK_URL;

  const webhook = new IncomingWebhook(url);

  // Send the notification
  (async () => {
    await webhook.send({
      text: 'I\'ve got news for you...',
      channel: '#marcoms'
    });
  })();

````

```auto

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 11, 2022, 5:26pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/9 "2022-01-11T17:26:35Z")

</div>

Thanks for providing that code @jphillips!

---

<div class="post-metadata">

**Author:** ![Senor\_Fiorano](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Senor\_Fiorano](https://community.auth0.com/u/Senor_Fiorano)\
**Post date:** [January 12, 2022, 7:54am UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/10 "2022-01-12T07:54:33Z")

</div>

Hi @dan.woda

Im running into the same issue (and very new to Auth0!) 😅

This Is my current code

```auto
exports.onExecutePostUserRegistration = async (event) => {
  const slack = require('slack-notify')(event.secrets.SLACK_WEBHOOK_URL);

  const message = `New User: ${event.user.email}`;
  const channel = '#ct_new_user_notifications'

  slack.success({
   text: message,
   channel: channel
  });
};

```

I have a module called slack-notify@latest

Please could you advise on getting this to work? Ive included a screenshot of the error when I test the action.

Many many thanks!

 ![Screenshot 2022-01-12 at 07.53.46](https://global.discourse-cdn.com/auth0/original/3X/c/7/c77b22ecf3fedcc8c5dd215f026670dcba62bfb0.png)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 12, 2022, 2:32pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/11 "2022-01-12T14:32:42Z")

</div>

Hi @Senor_Fiorano,

Welcome to Auth0!

The solution is stated directly in this thread, and is marked with “✅ Solution” . Is there some part of it that is not clear?

---

<div class="post-metadata">

**Author:** ![Senor\_Fiorano](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Senor\_Fiorano](https://community.auth0.com/u/Senor_Fiorano)\
**Post date:** [January 12, 2022, 3:53pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/12 "2022-01-12T15:53:20Z")

</div>

Hi @dan.woda  
Thanks for the prompt reply - much appreciated.

Due to my ‘noob-ness’ I incorrectly configured the ‘@slack/webhook’ module. All working as expected. Out of interest are you able to explain why the documentation I followed wont work?

> **[Write Your First Action](https://auth0.com/docs/customize/actions/write-your-first-action#create-an-action)**
>
> Learn how to write an Action, which includes choosing a flow, creating an Action and configuring it, and binding it to the flow.

Thanks again,

Fiorano

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 12, 2022, 6:31pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/13 "2022-01-12T18:31:10Z")

</div>

@Senor_Fiorano

I don’t have an explanation as to why that library is throwing the error, but we are actively working to update the documentation.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 27, 2022, 6:31pm UTC](https://community.auth0.com/t/must-use-import-to-load-es-module/76027/14 "2022-01-27T18:31:46Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
