-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Installing @aws-amplify/core adds node globals, which can make TS ignore potential errors #11736
Comments
Also remove the runtime dependency of @types/node-fetch because the new isomorphic-unfetch fixed the missing types and do not introduce the @types/node dependency. This fixes aws-amplify#11736
Hello, @bogdanailincaipnt 👋 and thank you for opening this issue. We are currently looking into this and potentially addressing it with a fix soon. We'll keep you updated on the progress, but appreciate your detailed findings and reproduction steps! |
The developer preview for v6 of Amplify has officially been released with improvements to TypeScript support and much more! Please check out our announcement and updated documentation to see what has changed. This issue should be resolved within the dev preview and upcoming General Availability for Amplify v6, but let us know with a comment if there are further issues. |
Nice! I tested with |
With the release of the latest major version of Amplify (aws-amplify@>6), this issue should now be resolved! Please refer to our release announcement, migration guide, and documentation for more information. |
Hello again, sorry to say this, but I found that the issue still occurs when importing from If you comment out the line that does My goal is to be able to specify where I want global types from |
It might be caused by one of these lines: amplify-js/packages/tsconfig.base.json Line 22 in b473532
|
Thank you for providing the detailed Stackblitz reproduction. Techinically the tsconfig.base.json shouldn't impact the output types, they are only useful for the library maintainers. But I see the problem from the sandbox. We'll investigate it and keep you post on this thread. |
@bogdanailincaipnt Hi, i started looking into this issue and all our reference in Amplify V6 for |
Hello @ashika112, I appreciate you looking into this! I opened the project locally as well, I think I may have found the cause. After running
|
@bogdanailincaipnt Thanks for the quick response and appreciated the deep dive :) the listed packages in the screenshot are all from |
@bogdanailincaipnt Confirming the Predictions is tree shaken out from |
@bogdanailincaipnt can we close this issue in favor of the one opened in aws-sdk since there is not much we can do at our end? |
@ashika112 I think this issue should be closed only after the |
@bogdanailincaipnt Sorry you are right. Notice we have pinned dependencies on @aws-sdk/types. Will wait on reply on the other ticket. Thanks. Will mark it accordingly. |
Before opening, please confirm:
JavaScript Framework
Not applicable
Amplify APIs
Not applicable
Amplify Categories
Not applicable
Environment information
Describe the bug
Installing
@aws-amplify/core
(or one of its dependends) adds NodeJS globals, which can make TS ignore potential errors.The
@aws-amplify/core
package has the"@types/node-fetch"
dependency in the"dependencies"
list in its package.json.This is causing TS to think that NodeJS globals (eg.
process
) are available, even though we are developing for a browser environment.Among NodeJS globals there are also methods like
String.at
, orArray.at
, which are not supported in ES2020 for example. As you can see in the Stackblitz containers linked below, this can cause TS to miss some errors, since it has its target set asES2020
intsconfig.json
.Solution:
"@types/node-fetch"
and any other package related to types, react-native, or other devtools should be included in"devDependencies"
, instead of"dependencies"
(explanation: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#dependencies - "Please do not put test harnesses or transpilers or other "development" time tools in your dependencies object.", "If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.").I think this is important to solve, because there are a lot of users potentially affected by this. Vite for example sets its default target as
ES2020
(roughly).Expected behavior
TS should not be missing errors.
Reproduction steps
npx tsc
in the terminal@aws-amplify/core
is not installed: https://stackblitz.com/edit/vitejs-vite-knsnqf?file=package.json,src%2Fmain.ts&terminal=devnpx tsc
in the terminalYou can also hover over
process
,at
in themain.ts
file to see how TS sees them (as NodeJS globals, or as missing).Code Snippet
// Put your code below this line.
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: