-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Error: "Module '"[...]/@types/react/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag" #7741
Comments
Fixes apollographql#7741 Using `import React from 'react'` causes issues when the import makes its way into the d.ts file. Users without `esModuleInterop: true` or `allowSyntheticDefaultImports: true` (or `skipLibCheck: true`) in their tsconfig files will get errors from typescript about not being able to default-import using that syntax. This PR fixes the specific imports that would cause issues due to their types being re-exported in `@apollo/client`'s types.
Fixes apollographql#7741 Using `import React from 'react'` causes issues when the import makes its way into the d.ts file. Users without `esModuleInterop: true` or `allowSyntheticDefaultImports: true` (or `skipLibCheck: true`) in their tsconfig files will get errors from typescript about not being able to default-import using that syntax. This PR fixes the specific imports that would cause issues due to their types being re-exported in `@apollo/client`'s types.
Fixes apollographql#7741 Using `import React from 'react'` causes issues when the import makes its way into the d.ts file. Users without `esModuleInterop: true` or `allowSyntheticDefaultImports: true` (or `skipLibCheck: true`) in their tsconfig files will get errors from typescript about not being able to default-import using that syntax. This PR fixes the specific imports that would cause issues due to their types being re-exported in `@apollo/client`'s types.
Fixes apollographql#7741 Using `import React from 'react'` causes issues when the import makes its way into the d.ts file. Users without `esModuleInterop: true` or `allowSyntheticDefaultImports: true` (or `skipLibCheck: true`) in their tsconfig files will get errors from typescript about not being able to default-import using that syntax. This PR fixes the specific imports that would cause issues due to their types being re-exported in `@apollo/client`'s types.
Fixes apollographql#7741 Using `import React from 'react'` causes issues when the import makes its way into the d.ts file. Users without `esModuleInterop: true` or `allowSyntheticDefaultImports: true` (or `skipLibCheck: true`) in their tsconfig files will get errors from typescript about not being able to default-import using that syntax. This PR fixes the specific imports that would cause issues due to their types being re-exported in `@apollo/client`'s types.
Fixes apollographql#7741 Using `import React from 'react'` causes issues when the import makes its way into the d.ts file. Users without `esModuleInterop: true` or `allowSyntheticDefaultImports: true` (or `skipLibCheck: true`) in their tsconfig files will get errors from typescript about not being able to default-import using that syntax. This PR fixes the specific imports that would cause issues due to their types being re-exported in `@apollo/client`'s types.
Fixes #7741. Using `import React from 'react'` causes issues when the import makes its way into the d.ts file. Users without `esModuleInterop: true` or `allowSyntheticDefaultImports: true` (or `skipLibCheck: true`) in their tsconfig files will get errors from typescript about not being able to default-import using that syntax. This PR fixes the specific imports that would cause issues due to their types being re-exported in `@apollo/client`'s types.
@devrelm Alas, I think #7742 is affected by the same "problems" that led to my reverting 7584ae9. Clearly I should have left better notes about why that didn't work the last time, and you were right to wonder about the reasoning. While I agree with the goals behind this issue and #7742, switching to namespace imports seems to confuse bundlers like Rollup, which have trouble figuring out that properties like
I don't currently know of a good solution for this problem, so please let me know if you have any insights. Unfortunately, since these errors would cause problems for existing applications, while this issue (#7741) is one that existing applications are already coping with (for better or worse), I think we might have to revert PR #7742 if we can't find a better solution. |
This reverts commit 78bc4bc, which caused more problems than it solved.
This comment has been minimized.
This comment has been minimized.
A fix for this is coming in |
Intended outcome:
I should be able to import
@apollo/client
without needingallowSyntheticDefaultImports
oresModuleInterop
set in my tsconfig.Actual outcome:
When I import
@apollo/client
without theallowSyntheticDefaultImports
andesModuleImports
flags set in my tsconfig, I get a series of errors like this:Similar errors are produced for both
react
andzen-observable
.How to reproduce the issue:
To Reproduce:
@apollo/client
,graphql
, and@types/react
in a typescript-based repo@apollo/client
(I reproduced withApolloConsumer
, but it should also be reproducible with imports)@apollo/client
using the typescript compilerReproduction Example:
yarn run tsc
Versions
Other Notes
It looks like this has already been brought up a few times but hasn't been totally fixed yet:
allowSyntheticDefaultImports
to fix the errorI'll try to get a PR in to fix the issue, but it would be nice to know how the fix "caused more problems than it solved" so that I could avoid any of the same pitfalls.
The text was updated successfully, but these errors were encountered: