Skip to content
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

Unable to use with vite #2478

Closed
klarkc opened this issue Jun 10, 2021 · 31 comments
Closed

Unable to use with vite #2478

klarkc opened this issue Jun 10, 2021 · 31 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness p1 This is a high priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. workaround-available This issue has a work around available.

Comments

@klarkc
Copy link

klarkc commented Jun 10, 2021

Describe the bug

It is not possible to import the sdk using vite (which uses rollup to bundle). It fails because it imports node-only dependencies into browser environment.

Your environment

Vite 2.3.7 (rollup bundler) with Node 15.14.0

SDK version number

@aws-sdk/credential-provider-cognito-identity@3.18.0

Is the issue in the browser/Node.js/ReactNative?

Browser

Steps to reproduce

https://github.com/klarkc/aws-sdk-js-v3

cd tests/vite-project
yarn install
yarn build

Observed behavior

Error: 'request' is not exported by __vite-browser-external, imported by node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js

Looking in the file, I see why, it imports request from http that does not exists in browsers. It seems that other packages have the same problem (I've tested with @aws-sdk/client-cognito-identity, same result).

Expected behavior

Should build without errors

Additional context

Related issue: https://github.com/aws-amplify/amplify-js/issues/7499
Vite wont fix: vitejs/vite#1374 (comment)

@klarkc klarkc added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 10, 2021
@ajredniwja ajredniwja added this to In progress in Investigation Jun 17, 2021
@trivikr
Copy link
Member

trivikr commented Jun 30, 2021

Related: #1164 (comment)

@ajredniwja ajredniwja added needs-review This issue/pr needs review from an internal developer. and removed needs-triage This issue or PR still needs to be triaged. labels Dec 6, 2021
@jiahao-c
Copy link

jiahao-c commented Jan 4, 2022

Related: aws/aws-sdk-js#3673

@sinkersan
Copy link

Is there any updates? I run into the same issue.

@mdhelaluddin-ctg-bd
Copy link

@klarkc did you solve this?

@klarkc
Copy link
Author

klarkc commented Mar 14, 2022

@mdhelaluddin-ctg-bd in #2491 I solved only the occurrences in @aws-sdk/credential-provider-cognito-identity and @aws-sdk/client-cognito-identity packages

@dmost714
Copy link

Some the techniques used to get AWS Amplify working with vite may be applicable.

@FlorianWendelborn
Copy link

FlorianWendelborn commented May 31, 2022

Workaround for a vue 2 project. Add this to your vite.config.js:

export default defineConfig({
	resolve: {
  		alias: {
			"./runtimeConfig": "./runtimeConfig.browser"
		}
	}
})

And this to index.html:

<script>
	window.global = window;
</script>

(Via aws-amplify/amplify-js#9639 (comment))

@ajredniwja ajredniwja added the p1 This is a high priority issue label Jun 10, 2022
@ajredniwja ajredniwja removed their assignment Jun 10, 2022
@ajredniwja ajredniwja removed this from In progress in Investigation Jun 10, 2022
@kuhe
Copy link
Contributor

kuhe commented Jun 27, 2022

I can't reproduce this problem with vite 2.9.9 and "@aws-sdk/credential-provider-cognito-identity": "^3.118.0", the latest as of today.

The distributable file structure has changed since the original issue was reported. Most browser/node incompatibility issues can be resolved by ensuring any bundlers involved are following the runtimeConfig.browser alias specified in each @aws-sdk/***-client package's package.json.browser entry.

@kuhe kuhe added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. workaround-available This issue has a work around available. and removed needs-review This issue/pr needs review from an internal developer. labels Jun 27, 2022
@kuhe kuhe self-assigned this Jun 27, 2022
@github-actions
Copy link

github-actions bot commented Jul 5, 2022

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jul 5, 2022
@dwightwatson
Copy link

I have this issue with vite 2.9.11 and amazon-location-helpers 1.1.1 which depends on AWS Amplify and Cognito. Specifically I'm using Vite as configured by the Laravel framework - happy to provide a repro if helpful.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. labels Jul 6, 2022
@MagnusHJensen
Copy link

What is the status on this? I'm seeing similar issues with Vite 3.0.0 and @AWS-SDK ^3.118.0 packages.

[ERROR] No matching export in "../../node_modules/@aws-sdk/credential-provider-web-identity/dist-es/index.js" for import "fromTokenFile"

    ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveWebIdentityCredentials.js:2:9:
      2 │ import { fromTokenFile } from "@aws-sdk/credential-provider-web-...
        ╵          ~~~~~~~~~~~~~

✘ [ERROR] No matching export in "../../node_modules/@aws-sdk/credential-provider-web-identity/dist-es/index.js" for import "fromTokenFile"

    ../../node_modules/@aws-sdk/credential-provider-node/dist-es/defaultProvider.js:6:9:
      6 │ import { fromTokenFile } from "@aws-sdk/credential-provider-web-...
        ╵          ~~~~~~~~~~~~~

✘ [ERROR] No matching export in "../../node_modules/@aws-sdk/credential-provider-web-identity/dist-es/index.js" for import "fromTokenFile"

    ../../node_modules/@aws-sdk/credential-providers/dist-es/fromTokenFile.js:3:9:
      3 │ import { fromTokenFile as _fromTokenFile, } from "@aws-sdk/crede...

@takayamaki
Copy link

There is a workaround in amplify docs.

https://ui.docs.amplify.aws/react/getting-started/troubleshooting#vite

@FlorianWendelborn
Copy link

@takayamaki it's great that a workaround exists, but it's quite a demand that users pollute their globals just to get some random library to work. The library shouldn't be written in such a way that makes this necessary

@jhubbardsf
Copy link

What is the status on this? I'm seeing similar issues with Vite 3.0.0 and @AWS-SDK ^3.118.0 packages.

[ERROR] No matching export in "../../node_modules/@aws-sdk/credential-provider-web-identity/dist-es/index.js" for import "fromTokenFile"

    ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveWebIdentityCredentials.js:2:9:
      2 │ import { fromTokenFile } from "@aws-sdk/credential-provider-web-...
        ╵          ~~~~~~~~~~~~~

✘ [ERROR] No matching export in "../../node_modules/@aws-sdk/credential-provider-web-identity/dist-es/index.js" for import "fromTokenFile"

    ../../node_modules/@aws-sdk/credential-provider-node/dist-es/defaultProvider.js:6:9:
      6 │ import { fromTokenFile } from "@aws-sdk/credential-provider-web-...
        ╵          ~~~~~~~~~~~~~

✘ [ERROR] No matching export in "../../node_modules/@aws-sdk/credential-provider-web-identity/dist-es/index.js" for import "fromTokenFile"

    ../../node_modules/@aws-sdk/credential-providers/dist-es/fromTokenFile.js:3:9:
      3 │ import { fromTokenFile as _fromTokenFile, } from "@aws-sdk/crede...

@MagnusHJensen Did you ever find a solution to this?

@trivikr
Copy link
Member

trivikr commented Nov 15, 2022

There is no error in vite 3.2.4 dev/build command with @aws-sdk/credential-provider-cognito-identity@3.210.0.
I followed Getting Started Guide from vite.

$ yarn create vite
...
success Installed "create-vite@3.2.1" with binaries:
      - create-vite
      - cva
✔ Project name: … vite-project
✔ Select a framework: › Vanilla
✔ Select a variant: › TypeScript

Scaffolding project in /Users/trivikr/workspace/vite-project...
...

$ cd vite-project

$ yarn vite --version
vite/3.2.4 darwin-x64 node-v16.18.0

$ yarn add @aws-sdk/credential-provider-cognito-identity@3.210.0 --exact
...

# Add import in src/main.ts
$ sed -i "1s|^|import '@aws-sdk/credential-provider-cognito-identity';\n|" src/main.ts

$ yarn dev
... no issues

$ yarn build
...
vite v3.2.4 building for production...
✓ 360 modules transformed.
dist/assets/typescript.f6ead1af.svg   1.40 KiB
dist/index.html                       0.44 KiB
dist/assets/index.acb3e620.js         1.40 KiB / gzip: 0.72 KiB
dist/assets/index.d5a34e39.css        1.19 KiB / gzip: 0.62 KiB
✨  Done in 2.90s.

@trivikr
Copy link
Member

trivikr commented Nov 15, 2022

Is this issue still reproducible for you?
If yes, can you provide repro steps?

@trivikr trivikr added the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Nov 15, 2022
@klarkc
Copy link
Author

klarkc commented Nov 15, 2022

@trivikr did an upgrade to vite 2.9.15 and @aws-sdk/credential-provider-cognito-identity to 3.210.0, and it's working normally now: klarkc/aws-sdk-js-v3@c182359

@dwightwatson
Copy link

Vite 3.2.4, @aws-sdk/credential-provider-cognito-identity 3.211.0 and I still can't complete a build with Vite. Though it looks like the error might have moved to @aws-sdk/client-cloudwatch-logs now?

'request' is not exported by __vite-browser-external, imported by node_modules/@aws-sdk/client-cloudwatch-logs/node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js
file: /Users/dwight/Sites/app/node_modules/@aws-sdk/client-cloudwatch-logs/node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js:4:9
2: import { ProviderError } from "@aws-sdk/property-provider";
3: import { Buffer } from "buffer";
4: import { request } from "http";
            ^
5: /**
6:  * @internal
error during build:
Error: 'request' is not exported by __vite-browser-external, imported by node_modules/@aws-sdk/client-cloudwatch-logs/node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js
    at error (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
    at Module.error (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:12429:16)
    at Module.traceVariable (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:12788:29)
    at ModuleScope.findVariable (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:11440:39)
    at FunctionScope.findVariable (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:6372:38)
    at ChildScope.findVariable (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:6372:38)
    at FunctionScope.findVariable (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:6372:38)
    at ChildScope.findVariable (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:6372:38)
    at Identifier.bind (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:7439:40)
    at CallExpression.bind (file:///Users/dwight/Sites/app/node_modules/rollup/dist/es/shared/rollup.js:5269:23)

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Nov 16, 2022
@FlorianWendelborn
Copy link

@dwightwatson can you make sure that all sub-dependencies are also up-to-date? The easiest way is to do that is to uninstall the package and then reinstall it at the desired version

@dwightwatson
Copy link

Yeah, tried that. Perhaps my issue is that my entry point is the specific amazon-location-helpers library instead.

yarn remove amazon-location-helpers
yarn add amazon-location-helpers --dev
yarn run build

@trivikr
Copy link
Member

trivikr commented Nov 18, 2022

Vite 3.2.4, @aws-sdk/credential-provider-cognito-identity 3.211.0 and I still can't complete a build with Vite. Though it looks like the error might have moved to @aws-sdk/client-cloudwatch-logs now?

@dwightwatson I'm not able to repro it with @aws-sdk/client-cloudwatch-logs@3.213.0.
Can you provide the steps you're following, or a repro repo?

$ yarn create vite
...
success Installed "create-vite@3.2.1" with binaries:
      - create-vite
      - cva
✔ Project name: … vite-project
✔ Select a framework: › Vanilla
✔ Select a variant: › TypeScript

Scaffolding project in /Users/trivikr/workspace/vite-project...
...

$ cd vite-project

$ yarn vite --version
vite/3.2.4 darwin-x64 node-v16.18.0

$ yarn add @aws-sdk/client-cloudwatch-logs@3.213.0 --exact
...
├─ uuid@8.3.2
└─ vite@3.2.4
Done in 4.49s.

# Add import in src/main.ts
$ sed -i "1s|^|import '@aws-sdk/client-cloudwatch-logs';\n|" src/main.ts

$ yarn dev
... no issues in build or on opening webpage on http://localhost:5173/

$ yarn build
...
vite v3.2.4 building for production...
✓ 360 modules transformed.
dist/assets/typescript.f6ead1af.svg   1.40 KiB
dist/index.html                       0.44 KiB
dist/assets/index.acb3e620.js         1.40 KiB / gzip: 0.72 KiB
dist/assets/index.d5a34e39.css        1.19 KiB / gzip: 0.62 KiB
✨  Done in 2.90s.

@trivikr trivikr added the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Nov 18, 2022
@dwightwatson
Copy link

I've got a repro repo here: https://github.com/dwightwatson/vite which fails when running yarn run build

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Nov 24, 2022
@alex-ironside
Copy link

Any news on this issue?

@Amplitude88
Copy link

Any news on this? I can't use AWS-sdk/credentials-provider with sveltekit 1.0 and vite v4.

The error is:

the requested module '/node_modules/.vite/deps/@AWS-SDK credential-providers doesn't export a function like "fromEnv"

But this is written and it seems to be an issue by the credentials-provider

@kylemichaelreaves
Copy link

Any news on this? I can't use AWS-sdk/credentials-provider with sveltekit 1.0 and vite v4.

The error is:

the requested module '/node_modules/.vite/deps/@AWS-SDK credential-providers doesn't export a function like "fromEnv"

But this is written and it seems to be an issue by the credentials-provider

I have the same issue with Vite 4 and the aws-sdk/credentials-provider

@trivikr
Copy link
Member

trivikr commented Feb 15, 2023

I've got a repro repo here: dwightwatson/vite

This issue is not with the direct import of AWS SDK for JavaScript (v3).
I see that you'd created an issue with amazon-location-samples which was closed because of inactivity
https://github.com/aws-samples/amazon-location-samples/issues/193

This issue is discussed in Amplify in aws-amplify/amplify-js#9639, and the solution is to update your vite config as follows:

  resolve: {
    alias: {
      "./runtimeConfig": "./runtimeConfig.browser",
    },
  },

Any news on this? I can't use AWS-sdk/credentials-provider with sveltekit 1.0 and vite v4.

@Amplitude88 Is there a repro I can look at?

I have the same issue with Vite 4 and the aws-sdk/credentials-provider

@kylemichaelreaves Do you have a repro I can look at?

@trivikr trivikr added the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Feb 15, 2023
@trivikr
Copy link
Member

trivikr commented Feb 15, 2023

There is no error in vite 4.1.0 dev/build command with @aws-sdk/credential-provider-cognito-identity@3.271.0.
I followed Getting Started Guide from vite.

$ yarn create vite
...
success Installed "create-vite@4.1.0" with binaries:
      - create-vite
      - cva
✔ Project name: … vite-project
✔ Select a framework: › Vanilla
✔ Select a variant: › TypeScript

Scaffolding project in /Users/trivikr/workspace/vite-project...
...

$ cd vite-project

$ yarn set version stable 
➤ YN0000: Retrieving https://repo.yarnpkg.com/3.4.1/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-3.4.1.cjs
➤ YN0000: Done in 0s 407ms

$ yarn

$ yarn vite --version
vite/4.1.1 darwin-arm64 node-v16.19.0

$ yarn add @aws-sdk/credential-provider-cognito-identity@3.271.0 --exact
...

# Add import in src/main.ts
$ sed -i "1s|^|import '@aws-sdk/credential-provider-cognito-identity';\n|" src/main.ts

$ yarn dev
... no issues

$ yarn build
...
vite v4.1.1 building for production...
✓ 6 modules transformed.
dist/index.html                      0.45 kB
dist/assets/typescript-f6ead1af.svg  1.44 kB
dist/assets/index-3443e464.css       1.24 kB │ gzip: 0.64 kB
dist/assets/index-5f8bed07.js        1.44 kB │ gzip: 0.74 kB

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Feb 16, 2023
@trivikr trivikr added the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Feb 20, 2023
@github-actions
Copy link

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Feb 23, 2023
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. closed-for-staleness p1 This is a high priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. workaround-available This issue has a work around available.
Projects
None yet
Development

No branches or pull requests