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

Fix: Use default exports for humps library #22

Merged
merged 1 commit into from
Feb 23, 2025
Merged

Conversation

hkamran2
Copy link
Contributor

Issue

Currently, running in ESM mode is causing failures due to the way humps is imported and bundled by tsup. The humps library provides uses default exports to export it's functionality.

This becomes a problem for ESM bundling as tsup just includes the following line in the index.min.mjs bundle:

import { camelizeKeys, decamelize, decamelizeKeys } from 'humps';

Running in ESM mode causes failures because named exports are not present in the humps module.

Fix

Use default exports.

Steps to reproduce

  1. Initialise a simple ESM package locally.
  2. Run npm install @quranjs/api to install the package.
  3. Import the functionality and run the script. For example:
import { quran } from "@quranjs/api";

const response = await quran.v4.audio.findChapterRecitationById(1);

console.log(response)
  1. You should see the following error message:
import { camelizeKeys, decamelize, decamelizeKeys } from 'humps';
         ^^^^^^^^^^^^
SyntaxError: Named export 'camelizeKeys' not found. The requested module 'humps' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'humps';
const { camelizeKeys, decamelize, decamelizeKeys } = pkg;

Note on testing

I've tested this change using pnpm link to verify the changes.

I've thought hard about including unit tests but vitest does transpilation of imported modules behind the scenes due to which this issue is hard to reproduce while testing.

The humps library provides uses default exports to export it's functionality.

This becomes a problem for ESM bundling as tsup just includes the following line in the bundle:

import { camelizeKeys, decamelize, decamelizeKeys } from 'humps';

Running in ESM mode causes failures because named exports are not present in the humps module.
Copy link

vercel bot commented Feb 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 21, 2025 7:48am

@ahmedriad1
Copy link
Collaborator

Thanks a lot for your PR, JAK!

@ahmedriad1 ahmedriad1 merged commit 07a6b5b into quran:dev Feb 23, 2025
4 checks passed
Copy link

🎉 This PR is included in version 1.7.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants