aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.13k stars 579 forks source link

Vite error during build when using '@aws-sdk/credential-provider-node' #6409

Open gnemanja opened 3 months ago

gnemanja commented 3 months ago

Checkboxes for prior research

Describe the bug

An error is thrown during build when using "import { defaultProvider } from '@aws-sdk/credential-provider-node';". Error: node_modules/@smithy/shared-ini-file-loader/dist-es/getHomeDir.js (2:9): "sep" is not exported by "__vite-browser-external", imported by "node_modules/@smithy/shared-ini-file-loader/dist-es/getHomeDir.js".

SDK version number

@aws-sdk/credential-provider-node@latest

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node version: v21.4.0; We are using QWIK which is similar to React

Reproduction Steps

import { defaultProvider } from '@aws-sdk/credential-provider-node';

export const sendMail = server$(()=>{
   const a = defaultProvider;
})

Observed Behavior

Screenshot 2024-08-24 at 20 43 31

Expected Behavior

Successful build

Possible Solution

No response

Additional Information/Context

I tried many solutions for similar problems found on your Github, but they didn't work. The only solution that did anything was including node vite polyfills plugin, but it gives another issue:

node_modules/@smithy/shared-ini-file-loader/dist-es/loadSharedConfigFiles.js (7:9): "slurpFile" is not exported by "__vite-browser-external", imported by "node_modules/@smithy/shared-ini-file-loader/dist-es/loadSharedConfigFiles.js".

zshzbh commented 2 months ago

Thanks for the feedback! I can't reproduce this issue in React app. I will try to reproduce this in qwik if I can, may I know if there's any certain version of qwik you are using?

gnemanja commented 2 months ago

We are currently on 1.5.6, but I am pretty sure you can use the latest stable as well :) Thanks :)

dwright20 commented 2 months ago

running into this as well. Any work around @gnemanja ?

manniniandrea commented 3 weeks ago

Seems like this is a vite misconfiguration issue: https://github.com/vitejs/vite/issues/7821 you need to specify node builtin modules in your vite config otherwise it'll try to bundle them throwing those errors