Closed thany closed 3 years ago
Yes, TSDX indeed ignores tsconfig.json#compilerOptions.target
; it transpiles to esnext
via the TS compiler, then runs Babel, as you can see in the source code here:
That comment was written by me as I also learned that the hard way in https://github.com/formium/tsdx/issues/413#issuecomment-570827672 / https://github.com/formium/tsdx/pull/130#issuecomment-569375532 / https://github.com/formium/tsdx/pull/415 .
I removed the option from the templates entirely in https://github.com/formium/tsdx/pull/466 (where it was even more confusingly set to es5
) but I agree there should be more explicit prompting to the user when these are encountered.
I recently added comments to all template tsconfig
s in https://github.com/formium/tsdx/pull/864 (realized in https://github.com/formium/tsdx/issues/483 and #489 that you can add comments in tsconfig.json
) so it might be good to add back in target: "esnext"
to the templates with a comment that it will be overridden.
In https://github.com/formium/tsdx/issues/760#issuecomment-692979270 I mentioned logging warnings for things that can't actually be configured, which is something that should definitely be done.
maybe respect
browserslist
inpackage.json
?
TSDX uses @babel/preset-env
by default which uses browserslist
by default. So it should work with whatever configuration the version of browserslist
allows. I manually tested this with .browserslistrc
in https://github.com/formium/tsdx/issues/655#issuecomment-695843723 and confirmed it worked, but do still need to write an integration test for that per that comment. It was mentioned in the v0.14.0 release notes as well.
Not sure why browserslist
in package.json
didn't work for you, possibly a versioning thing or maybe some babelrc
changes, would need more of a repro to test. But I'd recommend trying one of the other configuration options since at least one of them definitely works for me.
@agilgur5 Adding .browserslistrc
seems NOT working for me, the *.cjs.production.js
is ok which is properly transpiled. But *.cjs.development.js
is not, I can see things like a ?? b
Current Behavior
Modern code is not getting transpiled to the
target
specified intsconfig.json
.Expected behavior
It should respect the
target
option and transpile to that.Suggested solution(s)
I dunno, if
target
is undiserable or whatever, maybe respectbrowserslist
inpackage.json
? Because that it also doesn't do. Otherwise it should just pick uptarget
intsconfig.json
. Or I guess it should pick up something, anything, in order to make transpilation happen to a target of my choosing.Additional context
Currently it does only very moderate transpilation, for instance
a ?? b
is transpiled, but{ ...a, ...b }
is not. Even settingtarget
to a ridiculouses3
doesn't transpile any more (or less) than setting it toesnext
. There should be some difference between the two, wouldn't you say?So it is transpiling to some kind of target, but which one?... I don't know, but not my target, that's for sure.
Your environment
Why are these scripts never seeing my Firefox browser? 🤨 Anyway, maybe it also helps to see my
tsconfig.json
:To the question "why do you need this?" I can answer simply: because I need to test stuff in this library on old browsers. Maybe libraries should not be transpiled. Maybe they should be. But that is an opinion not quite relevant to this issue. Just wanted to get that off the tables.