Closed klarkc closed 1 year ago
Is there any updates? I run into the same issue.
@klarkc did you solve this?
@mdhelaluddin-ctg-bd in https://github.com/aws/aws-sdk-js-v3/pull/2491 I solved only the occurrences in @aws-sdk/credential-provider-cognito-identity
and @aws-sdk/client-cognito-identity
packages
Some the techniques used to get AWS Amplify working with vite may be applicable.
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 https://github.com/aws-amplify/amplify-js/issues/9639#issuecomment-1049158644)
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.
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.
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.
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...
@dwightwatson @MagnusHJensen
could you provide a minimal reproduction repository?
Here's an example from my use-case which uses Vite and AWS's amazon-location-helpers
package: https://github.com/dwightwatson/vite
There is a workaround in amplify docs.
https://ui.docs.amplify.aws/react/getting-started/troubleshooting#vite
@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
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?
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.
Is this issue still reproducible for you? If yes, can you provide repro steps?
@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@c18235998024eb03e75e34e9bf47003ab067c541
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)
@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
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
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.
I've got a repro repo here: https://github.com/dwightwatson/vite which fails when running yarn run build
Any news on this issue?
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
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
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 https://github.com/aws-amplify/amplify-js/issues/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?
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
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.
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.
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
Observed behavior
Looking in the file, I see why, it imports
request
fromhttp
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: https://github.com/vitejs/vite/issues/1374#issuecomment-754820938