-
Notifications
You must be signed in to change notification settings - Fork 599
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-sdk/core or @aws-sdk/types tells TS that NodeJS globals are available, which can make TS ignore potential errors in browsers #6413
Comments
Hey @bogdanailincaipnt , Thanks for the feedback! I can reproduce this issue and this issue also exists in other AWS clients. For example I can see the issue also exists in import {S3Client} from "@aws-sdk/client-s3";
console.log(S3Client);
process.env = {};
console.log(process.env);
export {}; From TS doc -
So this is expected that TS would still look through I will bring this issue to the team to see if there's anything we can do. Thanks! |
Hey @bogdanailincaipnt , Just got back from the team- It seems that any package written (with node like we do) will probably face this problem in the browser, we can't really avoid that since we do need to use node APIs/internals. we also offer the browser variant (if the bundler understands the relevant metadata) A workaround idea would be - put business logic in a file/folder and import the aws specific stuff in a separate file. We also want to check if the build fails on your end? If the build fails then it would be a high priority task for AWS SDK team. Thanks! |
Hey @zshzbh , fortunately the build does not fail on my end. I am using Vite as the bundler. Should I not be having this issue ? Note that I am actually using the Thanks! |
This SDK is written for Node.js and offers browser compatibility via bundler metadata in package.json for file replacement. I believe the only way to remove Node.js global types is to make all platform-specific code injectable. This would change the basic API contract that most users are accustomed to, so we are not planning on doing it. As a possible alternative, Biome and eslint offer noRestrictedGlobals to help you catch errors. |
I see a lot of people are having this problem with other packages as well. microsoft/TypeScript#37053 There are some ideas here mobxjs/mobx#3583 but I don't know if they can be used for aws-sdk. |
There's also a potential solution for me to use https://github.com/ds300/patch-package and remove all occurences of |
Any update on this issue or a timeline as to when we can expect a fix? Thanks! |
Checkboxes for prior research
Describe the bug
Installing
@aws-sdk/core
or@aws-sdk/types
tells TS that NodeJS globals are available, which can make TS ignore potential errors in browsers.Related issue and more info, context: aws-amplify/amplify-js#11736
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Browser
Details of the browser/Node.js/ReactNative version
Chrome: 128.0.6613.84
Reproduction Steps
https://stackblitz.com/edit/vitejs-vite-gmzgbg?file=src%2Fmain.ts
npm install
to finish.process.env
, TS shows us that NodeJS globals are available.import '@aws-sdk/core';
, the errors show up. They should show up either way, because I've specified"types": [],
intsconfig.json
, so global types from@types/node
should not be included, even though I've installed the@types/node
package.Observed Behavior
See aws-amplify/amplify-js#11736
Expected Behavior
See aws-amplify/amplify-js#11736
Possible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: