privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.8k stars 154 forks source link

ERR_PACKAGE_PATH_NOT_EXPORTED when using tsx with execa #673

Closed ansf closed 3 weeks ago

ansf commented 3 weeks ago

Acknowledgements

Minimal reproduction URL

https://github.com/ansf/tsx-execa

Problem & expected behavior (under 200 words)

When using tsx with execa, I see an error Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in ./node_modules/unicorn-magic/package.json (see reproducer)

To be honest, I am not sure if this is an issue of tsx or execa (or unicorn-magic). So please let me know, if I should report it to execa instead. 👍

Bugs are expected to be fixed by those affected by it

Compensating engineering work will speed up resolution and support the project

ansf commented 3 weeks ago

Sorry, I found this issue, which describes the same issue and describes how to fix it on our side! 🙏 https://github.com/sindresorhus/execa/issues/1159

privatenumber commented 3 weeks ago

I actually ran into this myself as well.

The problem is happening because the import gets converted to require under the hood, so it doesn't actually get the import condition. But you can just pass that in yourself:

tsx -C import ./file