Skip to content

fix: handle ESM default export in TS configs, fix backtick escaping, remove dead code#71

Open
staging-devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1774038193-fix-esm-default-export-and-backtick-escaping
Open

fix: handle ESM default export in TS configs, fix backtick escaping, remove dead code#71
staging-devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1774038193-fix-esm-default-export-and-backtick-escaping

Conversation

@staging-devin-ai-integration
Copy link

@staging-devin-ai-integration staging-devin-ai-integration bot commented Mar 20, 2026

Summary

Three bug fixes:

  1. ESM default export not extracted for TypeScript configs (fixes Problems with ESM Tailwind config default export and handling of prefix in Typewind #69, fixes Generating types breaks with Tailwind CSS v3.3 #44): When tailwind.config.ts uses export default, esbuild converts it to CJS with a .default property. createTypewindContext() was passing the raw eval result (containing { default: configObj }) to resolveConfig() instead of extracting configObj. Fixed by using evalResult.default ?? evalResult to handle both ESM and CJS exports.

  2. Incomplete backtick escaping in babel plugin: String.replace() with a string first argument only replaces the first occurrence. If the generated code contained multiple backticks, subsequent ones were unescaped, causing syntax errors in the eval'd error message. Fixed by using a regex with the global flag (/\/g`).

  3. Unused dead code in vite example: Removed leftover debugging variable (const t = { a: 'b' }) committed in adc6629.

Review & Testing Checklist for Human

  • Create a test project with tailwind.config.ts using export default { ... } and verify npx typewind generate works correctly
  • Verify the babel plugin handles expressions containing template literals (backticks) without crashing
  • Run npm test — all 6 snapshot tests pass with these changes

Notes

The ESM default export bug affects both cli.ts (type generation) and evaluate.ts (babel plugin evaluation) since they share createTypewindContext() from utils.ts.

Link to Devin session: https://staging.itsdev.in/sessions/4344bd04228f492c8a4e8f6b0a9f0e13
Requested by: @Mokshit06


Staging: Open in Devin

…remove dead code

- Fix ESM default export handling in createTypewindContext (fixes #69, #44):
  When a tailwind.config.ts uses `export default`, esbuild converts it to
  CJS with a .default property. The eval result was used directly without
  extracting .default, causing resolveConfig to receive the wrong object.

- Fix incomplete backtick escaping in babel plugin:
  String.replace with a string argument only replaces the first occurrence.
  Changed to regex with global flag to escape all backticks in error messages.

- Remove unused dead code from vite example (leftover from adc6629)

Co-Authored-By: mokshitjain2006+coggittest2003@gmail.com <mokshitjain2006@gmail.com>
@staging-devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
typewind Error Error Mar 20, 2026 8:25pm

Request Review

Copy link
Author

@staging-devin-ai-integration staging-devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Staging: Open in Devin
Debug

Playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with ESM Tailwind config default export and handling of prefix in Typewind Generating types breaks with Tailwind CSS v3.3

1 participant