Vite is not compile when add aws-amplify package. It show issue
[vite] Dep optimization failed with error:
[vite]: Rollup failed to resolve import "@aws-sdk/credential-provider-cognito-identity"....
vite-app.from npm (or yarn | pnpm) install aws-amplify or in my case only use 2 sub-packages @aws-amplify/auth and @aws-amplify/core.
run npm run dev.
Error will be response like this:
vite v1.0.0-rc.4
[vite] Optimizable dependencies detected:
vue, @aws-amplify/auth, @aws-amplify/core
[vite] Dep optimization failed with error:
[vite]: Rollup failed to resolve import "@aws-sdk/credential-provider-cognito-identity" from "node_modules/.pnpm/@aws-amplify/[email protected]/node_modules/@aws-amplify/core/lib-esm/Credentials.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`rollupInputOptions.external`
...
rollupInputOptions: {
external: [/@aws-sdk/],
},
to vite.config.ts. run npm run dev will work.
aws-amplify package. In my case i write code to signin into cognitoimport Amplify from '@aws-amplify/core';
import Auth from '@aws-amplify/auth';
Amplify.configure({...})
// --- later
AuthService.client.signIn(i.email, i.password).then((r) => ...);
save file and see in terminal new error:
$ vite
vite v1.0.0-rc.4
[vite] Optimizable dependencies detected:
rxjs, vue, @aws-amplify/auth, @aws-amplify/core, numeral
Dev server running at:
> Local: http://localhost:3000/
> Network: http://192.168.0.103:3000/
[vite] Failed to resolve module import "@aws-sdk/credential-provider-cognito-identity/dist/es/index.js". (imported by /@modules/@aws-amplify/auth.js)
vite version: v1.0.0-rc.4vue version (from yarn.lock or package-lock.json)@vue/compiler-sfc versionvite or vite build with the --debug flag.suspect it's AWS fault. i tried to replicate and got a slightly different error. theyre not shipping esm files

confirm new info about aws-sdk aws-amplify and any stupid projects from amazon... look like almost their project consider default build by webpack. Alot people complains about unsupport , error prone etc when use with other solution without webpack.
https://github.com/aws/aws-sdk-js/issues/1769#issue-267403803
this is one of issue we can interview. Issue come from Amazon's team and it unsupport rollup.. Hope anyone have exp can know a workaround solution.
As @sw-yx said.It is also happend in @aws-sdk/credential-provider-cognito-identity.You should ask aws-sdk to fix their es exports.
(leaving breadcrumbs) related issue - https://github.com/aws/aws-sdk-js-v3/issues/1364 - think this was a bad release that we pinned to and we need to update the versions.
Most helpful comment
(leaving breadcrumbs) related issue - https://github.com/aws/aws-sdk-js-v3/issues/1364 - think this was a bad release that we pinned to and we need to update the versions.