bamada / nest-slack-bolt

A NestJS module for seamless integration with Slack using the Bolt SDK. Simplify Slack bot development with decorators for message, event, action, and command handling.
https://www.npmjs.com/package/nestjs-slack-bolt
MIT License
26 stars 8 forks source link

Module is ESM while NestJS can only import CommonJS module #425

Open nkahoang opened 4 days ago

nkahoang commented 4 days ago

Hi,

I think one of the dependency/chore bots that you have had accidentally added in "type": "module" for this package, which renders it hard to use in a NestJS project.

Can you please remove it so it's just a normal CommonJS library? NestJS itself is not even ESM yet

Thank you

wnqueiroz commented 2 days ago

I was going to report the same problem here @nkahoang...

I'm going crazy trying to make it work, and converting the NestJS project to ESM doesn't seem right to me...

➜  yarn build && yarn start:prod
yarn run v1.22.22
$ nest build
Done in 8.18s.
yarn run v1.22.22
$ node dist/main
/home/wnqueiroz/slack-bot/dist/slack/slack.module.js:11
const nestjs_slack_bolt_1 = require("nestjs-slack-bolt");
                            ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/wnqueiroz/slack-bot/node_modules/nestjs-slack-bolt/dist/index.js from /home/wnqueiroz/slack-bot/dist/slack/slack.module.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 /home/wnqueiroz/slack-bot/node_modules/nestjs-slack-bolt/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Object.<anonymous> (/home/wnqueiroz/slack-bot/dist/slack/slack.module.js:11:29) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.16.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If this is not reverted, I will need to remove the package from the project which I really didn't want... I'm enjoying the project and trying to contribute. Upvote for @nkahoang.

wnqueiroz commented 2 days ago

Added in this commit BTW: https://github.com/bamada/nest-slack-bolt/commit/de65ef86fc1cbfcd9a82df3c9f571f883c28a849#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R7

I left it at version nestjs-slack-bolt@1.1.1 for now.