Skip to content

Comments

fix: better ES module support for App class#2632

Merged
zimeg merged 3 commits intoslackapi:mainfrom
vercel-partner-solutions:main
Sep 9, 2025
Merged

fix: better ES module support for App class#2632
zimeg merged 3 commits intoslackapi:mainfrom
vercel-partner-solutions:main

Conversation

@malewis5
Copy link
Contributor

Summary

Fix ES module named export for App class

TypeScript's compilation of export { default as App } from './App' to CommonJS doesn't create proper named exports for ES module interoperability.

Before:

  // ❌ Fails in ES modules
  import { App } from '@slack/bolt';
  // ✅ Workaround required  
  import pkg from '@slack/bolt';
  const { App } = pkg;

After:

  // ✅ Now works!
  import { App } from '@slack/bolt';
  // ✅ Still backward compatible
  import pkg from '@slack/bolt';
  const { App } = pkg;

Details

  • Changed from export { default as App } re-export pattern to explicit import + export
  • Maintains full backward compatibility with existing CommonJS usage
  • Only affects the App class export to minimize risk

Notes

  • The same issue still exists for the receiver classes, but I wanted to scope this to only the App class.
  • Here is a useful tool to check these issues: npx --yes @arethetypeswrong/cli --from-npm @slack/bolt -f json
"problems": {
    "NamedExports": [
      {
        "kind": "NamedExports",
        "implementationFileName": "/node_modules/@slack/bolt/dist/index.js",
        "typesFileName": "/node_modules/@slack/bolt/dist/index.d.ts",
        "isMissingAllNamed": false,
        "missing": [
          "App",
          "Logger",
          "ExpressReceiver",
          "SocketModeReceiver",
          "HTTPReceiver",
          "AwsLambdaReceiver",
          "Installation",
          "InstallURLOptions",
          "InstallationQuery",
          "InstallationStore",
          "StateStore",
          "InstallProviderOptions"
        ]
      }
    ]
  }

@malewis5 malewis5 changed the title fix: better ES module support f fix: better ES module support for App class Aug 25, 2025
@zimeg zimeg added enhancement M-T: A feature request for new functionality semver:patch labels Aug 25, 2025
@zimeg
Copy link
Member

zimeg commented Aug 25, 2025

Hey @malewis5! 👋 Thanks for sending this in and sharing such interesting tooling!

I'm a fan of this contribution in improvements for #2565 but I am not familiar of the strangeness the current release has? Testing with the following doesn't cause errors for me:

import { App } from "@slack/bolt";

const app = new App({ token: "example" });

await app.start();
$ npx tsc --allowJs --noEmit --esModuleInterop app.js

But please do let me know how else I can test this!

FWIW this "esModuleInterop" option is suspicious to me and removing it might require more upstream changes 👁️‍🗨️

@codecov
Copy link

codecov bot commented Aug 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.37%. Comparing base (73d15c1) to head (dbc8134).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2632   +/-   ##
=======================================
  Coverage   93.37%   93.37%           
=======================================
  Files          37       37           
  Lines        7581     7581           
  Branches      667      667           
=======================================
  Hits         7079     7079           
  Misses        497      497           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@malewis5
Copy link
Contributor Author

Hey @zimeg, we'll only see this crash at runtime not during typescript transpile. There's a good explanation of the issue here.

@malewis5
Copy link
Contributor Author

Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malewis5 Thank you for sharing those steps and more examples! 👾 ✨

I'm finding this change to be so helpful in similar setups of slack-samples/bolt-js-starter-template#119 while also remaining backward compatible so I think we're good to merge this for the next release 🚢

We should also revisit the other missing named exports noted in upcoming changes for #2565. I'll leave a comment with more detail, but am thinking named exports might be best?

Super appreciate this contribution and details shared! 🎁

@zimeg zimeg merged commit 44ceb2f into slackapi:main Sep 9, 2025
19 checks passed
@zimeg zimeg mentioned this pull request Sep 9, 2025
@zimeg zimeg added this to the 4.4.1 milestone Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla:signed enhancement M-T: A feature request for new functionality semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants