Skip to content

Fix css-tree import #109

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

Merged
merged 1 commit into from
Jan 15, 2025
Merged

Fix css-tree import #109

merged 1 commit into from
Jan 15, 2025

Conversation

Napam
Copy link
Contributor

@Napam Napam commented Jan 15, 2025

I had an issue with my ESM build related to css-tree import (related to #89)

Had to do some digging here, but I believe I have found the root issue:

css-tree's index.d.ts does not match their actual distributed code. Their index.d.ts file says that there is NO default export so if we would do this:

import cssTree from 'css-tree';

we would get a TypeScript error.

But when inspecting in css-tree's node_modules I see the following:

In package.json their main is "lib/index.js", and that file is module.exports = require('./syntax');, which is a default export.

Ideally they would fix this, but a "quickfix" for our case is to specify

// compilerOptions in tsconfig
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,

such that we can do

import cssTree from 'css-tree';

without getting any errors.

Something unexplainable

I still don't get how jest have managed to make it work though, but it could be how jest does dynamic imports that allows jest to not crash in this case. Either way jest still works with these changes.

Tested

I have tested this change on my ESM project and it fixed it. I have not tested this on a CJS project, but I think it should work.

@danomatic
Copy link
Owner

@Napam thank you for looking into this! It seems we've been bouncing back and force between breaking/fixing it for CJS and ESM and I think you've solved the mystery. I'll merge and build and see how it works for my CJS projects.

@danomatic danomatic merged commit e9ea15a into danomatic:main Jan 15, 2025
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.

2 participants