-
Notifications
You must be signed in to change notification settings - Fork 508
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
Default export not output as expected -- missing __esModule #165
Comments
confirmed that i have run into this issue before, but jared has a strong view that we shouldnt use default exports anyway and this is his tool so i didnt bother doing anything about it. if you'd like to introduce a warning, or error, or fix the output as long as it doesnt affect the experience for named exports, i'd be open to that |
Just experienced this bug too in my package ( Per @rtbenfield's example, if one is transpiling their code from ESM to CJS, they might be using default imports which will then fail when transpiled. This bug is caused by the Rollup config here: tsdx/src/createRollupConfig.ts Lines 108 to 109 in f6ecdc9
I think this option should be changed to respect the The problem with changing that code is that it doesn't import
Changing this option so that |
Ahh. Yeah I'm sorry about this guys. I don't use default exports and I can go in depth as why you should not either. We should probably just document this in the README if there is no quick fix |
@jaredpalmer the quick fix would be: esModule: require(opts.tsconfig).esModuleInterop, I can submit a PR for that, but it's pretty hacky so idk if that's acceptable. I think the big issue with not supporting default exports is that it limits |
Upon testing, the quick fix does not seem to work as Could make that the default arg for the option. The slightly less hacky way to "import" app root Lines 43 to 50 in 1a2e50c
|
I was just burned by this as well. I know that's not helpful feedback, but I wanted to ping this issue again so it gets attention. This is sort of an Achilles heel to this tool at the moment. |
Does it not work with 10.x? |
I started a new project just today, fresh install of tsdx, everything seemed okay, but when I tested out what I published it was off. Typings pointed to Here's the repo: https://github.com/benlesh/react-simple-vlist I've since flipped it to not use default exports for |
Have you tried?
Instead of This worked for me. Example project. |
Or just don't use this devil syntax. Named exports do the work better. |
Ran into this issue today. It's not that I (and some others) want to use Default Export but because some other tools require Default Export to work, namely Mocha Custom Reporter. |
Added a PR to resolve this in #327 following my previous suggestions above. As I and others have stated above, this is a pretty big blocker to adoption and causes lots of unexpected compatibility bugs with different tools, as well as unintended breaking changes for any libraries that try to adopt #327 respects the |
@agilgur5 as you know, tsdx is just formik's build system. I don't use default exports unless forced to by a framework (e.g. next.js or gatsby). I apologize for the frustration. Is there any workaround? |
@jaredpalmer ^ this workaround worked for me. https://github.com/ArchitectNow/cypress-testrail-reporter/blob/master/src/reporter.ts#L61 |
@nartc the workaround that @kunukn listed isn't entirely compatible. It'll make BUT if you use The import myThing from 'myThing' should transpile to const { default: myThing } = require('myThing') and not const myThing = require('myThing') As I've said in my above comments, the lack of |
I realized earlier today that there is a workaround for this in module.exports = {
rollup(config, options) {
config.output.esModule = true
return config
}
} My fix got merged today and should be out whenever the next release is cut, but in the meantime or for slightly older versions of |
Current Behavior
TSDX doesn't seem to have the expected output when building a package with a default export. The type definitions are output as expected, but the resulting
.js
file actually exports as{ default: /* value */ }
. I've created a minimal, reproducible example at rtbenfield/tsdx-default-export bootstrapped fromtsdx create
. This is my first time using TSDX and it is possible I am just doing something incorrectly.In the repo mentioned above, I changed the
sum
function to be a default export, then addedoutput.test.ts
which imports directly fromdist
instead ofsrc
.output.test.ts
logs the value ofimport sum from "../dist"
and is showingsum
to be{ default: ... }
instead of the actual function.Expected behavior
The
.js
output files indist
can be consumed as default exports (ex.import sum from "my-module"
) if the source file utilized default exports.Suggested solution(s)
Unsure, but willing to investigate if this is confirmed to be an issue. I know Webpack, but not Rollup, so it could be a good excuse for me to get some experience with it.
Additional context
Nothing relevant that I know of.
Your environment
The text was updated successfully, but these errors were encountered: