-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Vite apps will not build or run while using Amplify libraries with AWS-SDK #3673
Comments
any update on this? I have the exact same issue using SvelteKit |
@ErikCH please add these code to index.html,maybe can fix it. |
Vite actually respects the However, these problematic packages have more than one For example, the To be fair, this is undocumented behavior. The browser field spec never says which The SDK can fix this issue by removing the nested
|
@sodatea thank you for the sync up and update on this. attached the screenshot for reference: update:
|
Related to aws/aws-sdk-js-v3#2564 |
I don't have a |
I'm getting this error:
|
Hi @chovyprognos , while this is being worked on, have you tried this work around? IN this documentation. https://ui.docs.amplify.aws/ui/getting-started/installation?platform=vue |
I'm having this issue trying to build sveltekit site with vite and aws-amplify @ErikCH thanks for sending that im sure some variation of that is what I'll need for sveltekit. P.S. I've been watching your youtube for long time so when I come across issues and search only to see you always being a solutions guy two steps ahead of me for aws-amplify issues I'm just like man Erik is a man of the people. Keep it up |
@24jr Have you tried these three steps mentioned in aws-amplify/amplify-js#9639 This workaround for aws-amplify in SvelteKit has been working for me for sometime now. Let me know if I can help if you're facing any specific issues afterwards. |
@kaleabmelkie well that is for vue do you know how I do that in sveltekit?
then I add the adapter like this
now I need to add the resolve part
this is not working but something like this do you by chance know? |
The 'resolve' is not meant to be inside the adpater's options. It should be directly inside the 'kit.vite' object. |
@24jr Here's how it might look for your config: import adapter from '@sveltejs/adapter-node'
/** @type {import('@sveltejs/kit').Config} */
export default {
kit: {
target: '#svelte',
adapter: adapter({
// default options are shown
out: 'build',
precompress: false,
env: {
host: 'HOST',
port: 'PORT'
},
}),
vite: {
resolve: {
alias: {
'./runtimeConfig': './runtimeConfig.browser',
},
},
},
},
} P.S. it should work with any or no svelte adapters. (I've tried it with adapter-static, adapter-vercel & without any adapters). |
@kaleabmelkie Wow extremely helpful. I'm not well versed on what adapter is other than that is translates svelte code to a simple clean build of what is actually used. When you say without any adapters is there a built in default and dont need to import others necessarily? Like such? (which still gave
Now using adapter-node how you did successfully created the build files however there must be issue with how I'm using amplify-configure getting red 'Amplify.configure is not a function' on completion of build and when run
which I am using in my __layout.svelte file like
Is that how you did yours? there isnt like a main.js or anything (idk if ssr even doing anything but might be) |
I used a named See the last part of this comment: aws-amplify/amplify-js#9639 |
@kaleabmelkie I absolutely appreciate you. Everything is working great. Stay gold Side note I am having issue building it in aws amplify but that may be diff issue aws-amplify/amplify-hosting#2318 |
I'm using vite + react + amplify and I'm having the same phenomenon.
|
@yogarasu this is how mine is not sure if will work different than yours
|
This works - Amplify team has the libraries properly switching to the browser context with Webpack, but not with Vite/Rollup.
|
Vite doesn't work with aws amplify aws/aws-sdk-js#3673
I solved this issue thanks to this post: https://stackoverflow.com/questions/70938763/build-problem-with-react-vitejs-and-was-amplify In vite.config.js add: resolve: {
alias: {
'./runtimeConfig': './runtimeConfig.browser',
},
} |
Thanks! This is actually what fixed the problem for me. |
Still having the issue even after trying all of the rest of the solutions. I've been using [email protected] (but tried with Vite@latest as well) and React and it appears that Vite and the AWS SDK simply don't work together. |
@justinfarrelldev it does... there is something about your config that isn't quite right. Please post your error messages. Delete your .lock files, update your node modules. |
Using the full config in this answer also adds the necessary polyfills for |
I'm having the same issue with this one, |
@shinspiegel I don't want to muddy the waters since so many good workarounds and descriptions have already been posted here, and my understanding of exactly what is going wrong is minimal. However, the following For release builds I had to implement a separate hack adapted from the following:
Since I'm using Quasar I had to make the change in
Periodically I see comments indicating the problem might have been fixed in amplify. I regularly update The same goes for Vite. For example, over time I've seen comments saying a particular version fixes the problem, e.g. Note: I don't have a direct dev dependency on Vite since I'm using it within Quasar's build system. Instead, I depend on |
This solution worked for me. In case you're using Astro, which uses Vite, edit
Orginal answer can be found here |
add alias Then my
|
any one have a solution for this problem please this is very bad thing and amazon aws must solve it |
@aliHamid98 a workaround has been posted above your comment for Vite which you can use until this has been resolved |
I have recently encountered the issues and attempted to try the solution above but it did not work. What worked for me is the following with a different polyfill module.
|
Hi everyone, Thanks, |
Confirm by changing [ ] to [x] below to ensure that it's a bug:
Describe the bug
Customers using the Amplify library are not able to use Vite, a native ESM no-bundle dev server, for Vue, React and Preact. After installing the package customers trying to run the dev server will get this error.
Users trying to build their app will get this error.
After further research with the Amplify team we have found a workaround as illustrated in 7499.
This workaround explicitly tells Vite, which uses rollup, to alias the
runtimeConfig
to theruntimeConfig.browser
file.We believe the problem is that Vite doesn't respect the
browser
field in@aws-sdk/client-
package.json. This is a deliberate action made on the maintainers behalf, as outlined here.vitejs/vite#2329
okta/okta-auth-js#641
This is what we learned as discussed from this comment here.
@aws-sdk/credential-provider-imds
is only required by@aws-sdk/credential-provider-node
@aws-sdk/credential-provider-node
is defined inruntimeConfig.ts
within the@aws-sdk/client-*
packages.`Is it possible for the
@aws-sdk/client
libraries to update their package.json's so Vite, and other ESM bundlers would correctly use the correct browser packages, and not the Node built-ins, since it's not respecting thebrowser
field? The maintainer has recommended usingexports
as one possible solution.Anecdotally, this issue might also exist with Snowpack, another ESM dev server, however, it has a workaround by using the
--polyfill-node
pollyfill argument, that Vite does not have.Is the issue in the browser/Node.js?
Browse
SDK version number
Example: latest
To Reproduce (observed behavior)
I have a repo with the work around here.
To reproduce the issue remove the alias from the vite config, and the
<script>
tag in the index.html.Or create a new vite app
Install amplify
Add amplify to main.js file
Run the server and then try to build the server
Expected behavior
Dev server and builds should run without errors, or needing to add global and exports into script tag for HTML.
The text was updated successfully, but these errors were encountered: