Vite: Vite not working with aws-amplify package

Created on 6 Aug 2020  路  4Comments  路  Source: vitejs/vite

Describe the bug

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"....

Reproduction

  • setup fresh new vue project from 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`
...
  • try to add
rollupInputOptions: {
    external: [/@aws-sdk/],
},

to vite.config.ts. run npm run dev will work.

  • write code to use aws-amplify package. In my case i write code to signin into cognito
import 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)

System Info

  • required vite version: v1.0.0-rc.4
  • required Operating System: Macos 10.14.6
  • required Node version: v11.15
  • Optional:

    • npm/yarn version

      npm = 6.14.6 | pnpm = 5.14.2

    • Installed vue version (from yarn.lock or package-lock.json)

      no install, use default from vite

    • Installed @vue/compiler-sfc version

      "@vue/compiler-sfc": "^3.0.0-rc.1",

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
pending triage

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.

All 4 comments

suspect it's AWS fault. i tried to replicate and got a slightly different error. theyre not shipping esm files
image

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tbgse picture tbgse  路  4Comments

Hoverhuang-er picture Hoverhuang-er  路  3Comments

cyberalien picture cyberalien  路  3Comments

stefnotch picture stefnotch  路  3Comments

hyingreborn picture hyingreborn  路  3Comments