-
Notifications
You must be signed in to change notification settings - Fork 492
allowSyntheticDefaultImports flag in tsconfig.json #214
Comments
Hm... that readme section definitely need some additions. |
Aha, so the way you import modules depends on the create-react-app-ts version, is that correct? |
Simplified, it's about |
I see, It's a complicated question. Thanks for taking the time to answer. Anyway in my personal opinion due to the fact that by default Typescript (if I'm not wrong) comes with |
also note that with
with |
@Hotell interesting corner case. Does your code compile with dynamics imports and Also I dont know the details of your case but if you want to use babel a quick idea is to use CRA instead of CRA-typescript. Not sure if this has sense in your case. |
yup, so we had to switch to
Doesn't make much sense...would do double physical compilation ( running |
I just hit a similar situation where the normal build with |
@mlwilkerson good to know it... Also other question, maybe it should be a new issue, but in my case I had to install |
That doesn't make any sense, as
That's in the documentation so it's not an issue rather documented fact |
@mlwilkerson Anyway it is a subjective matter. I guess I like this point of view: https://en.wikipedia.org/wiki/Don%27t_Make_Me_Think |
@Hotell my |
@mlwilkerson , As you already might have figured out from reading the Using a custom To support one of the flags mentioned above, it would be required to change the @mlwilkerson , regarding the project you mentioned: I suppose the change listed was required since you used In general, I would not recommend to test code that includes dynamic |
To test code with dynamic imports seems problematic indeed. An option could be try to mock dynamicaly loaded code. |
Yes, @DorianGrey, you're correct about my situation. I'm still somewhat new to navigating the different module formats and loading environments, but yes, I do wonder about needing to change the way we are bundling the |
In my codebase, I am using regular imports:
And had a situation that app compiled and worked correctly, but jest tests were failing. I resolved this by modifying @Hotell maybe this may help. |
We've decide to get rid of default exports altogether, because there have been too many complications like this. See also:
And further evidence from how both TypeScript and Rollup have to dance around these default exports, namely:
|
This could shed some light for anyone interested. All this kind of small quirks seem to be related to https://www.npmjs.com/package/ts-jest#supports-synthetic-modules EDIT: I wrote this in a hurry whitout having read @DorianGrey's more elaborated answer. As complement to the thread here is a great article about modules and exports in es6: I think the issue can be closed. |
@mlwilkerson, don't you need Currently, in the starter App.tsx, you have
This goes through webpack file-loader. I think it uses commonjs modules and doesn't have a default export All these import methods work as well with
If you add a
Here I am running jest and changing the file extension .js <-> .tsx (remove If you don't want to turn on
or
|
@YagoLopez And if you use Babel it converts ES modules to CommonJS in a default preset plugin. more info |
Thanks @rmlevangelio. Javascript modules are really confusing. Hope we have a solid standard and straight way to manage modules soon. In the mean time I've opted to not to use synthetic imports in Typescript neither default imports for future projects. |
In "Importing a Component" section in https://github.com/wmonk/create-react-app-typescript/blob/master/packages/react-scripts/template/README.md it says:
Button.js
I had problems with this and had to use:
After some investigation I could use the first way using the flag
allowSyntheticDefaultImports: true
intsconfig.json
. I thought it could be useful for others to know it. Is it worth to make a pull request to add this to the README.md file?The text was updated successfully, but these errors were encountered: