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

TypeError: (0 , slack_notify_1.default) is not a function #34

Open
adamdry opened this issue Oct 10, 2022 · 4 comments
Open

TypeError: (0 , slack_notify_1.default) is not a function #34

adamdry opened this issue Oct 10, 2022 · 4 comments
Labels
help needed When the maintainer needs help fixing this issue

Comments

@adamdry
Copy link

adamdry commented Oct 10, 2022

This line:
const slack = SlackNotify(MY_SLACK_WEBHOOK_URL)

Gives the error TypeError: (0 , slack_notify_1.default) is not a function

This is the full class, inside a nestjs app:

import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { EnvVariableName } from '../../common/enum/EnvVariableName'
import SlackNotify from 'slack-notify'

@Injectable()
export class SlackNotifier {

    public constructor(configService: ConfigService) {
        const MY_SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/RANDOMCHARS'
        const slack = SlackNotify(MY_SLACK_WEBHOOK_URL)
    }

    public sendMsg(msg: string) {
        // this.slack.send(msg)
    }
}
@movses
Copy link

movses commented Oct 21, 2022

I had same issue.
Was forced to downgrade to 2.0.2 and add typings manually using this answer.
https://stackoverflow.com/questions/41292559/could-not-find-a-declaration-file-for-module-module-name-path-to-module-nam/51320328#51320328

@andrewchilds
Copy link
Owner

I was able to reproduce this locally with a vanilla nestjs install. After a bit of research, I found that adding "esModuleInterop": true to the project tsconfig.json file resolves this issue. See https://stackoverflow.com/a/61530428/440094 for more detail.

I've tried to make slack-notify available both as a CJS and ESM module. If anyone knows of another way to configure package.json that continues to provide support for both formats, while also resolving this issue without needing to add esModuleInterop flag, please chime in here.

@andrewchilds andrewchilds added the help needed When the maintainer needs help fixing this issue label Dec 2, 2022
@rohithadg
Copy link

Me too having same issue. I tried above workaround but no luck.
Does anyone has workaround?

@JayBox325
Copy link

I think this is the same issue I'm coming up against here on my Next 13 / react 18 app.

My code:

import SlackNotify from 'slack-notify'

export default function NotifySlack() {
    const MY_SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/xxx/yyy/zzz'
    const slack = SlackNotify(MY_SLACK_WEBHOOK_URL)

    slack.send('Hello!')
        .then(() => {
            console.log('notified slack!')
        }).catch((err) => {
            console.error('slack error', err)
        })
}

This is throwing the following in the browser when I fire this function: slack error TypeError: The "listener" argument must be of type Function. Received type object

This issue here is the only one that I seem to find when I try and find a solution, hopefully this is something simple to resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help needed When the maintainer needs help fixing this issue
Projects
None yet
Development

No branches or pull requests

5 participants