aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.06k stars 573 forks source link

Unable to bundle with rollup for Lambda deployment #1164

Closed monken closed 1 year ago

monken commented 4 years ago

Describe the bug I'm trying to use rollup to create a deployable bundle for Lambda.

SDK version number beta-5

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

Details of the browser/Node.js version 12

To Reproduce (observed behavior)

git clone https://github.com/monken/js-sdk-v3-rollup
yarn
yarn rollup -c

Expected behavior I expect rollup to find and resolve all dependencies.

Screenshots

./src/index.js → dist...
[!] Error: 'NodeHttpHandler' is not exported by node_modules/@aws-sdk/node-http-handler/build/index.js, imported by node_modules/@aws-sdk/client-sts/dist/es/runtimeConfig.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
monken commented 4 years ago

Generally speaking it seems that some bundlers might have issues with the export * from syntax used in many places. Explicit exports seem to resolve this specific issue and make three-shaking more efficient.

AllanZhengYP commented 4 years ago

Hi @monken

Can you elaborate which export * from exactly is causing this issue?

monken commented 4 years ago

The immediate export * from is defined in https://github.com/aws/aws-sdk-js-v3/blob/master/packages/node-http-handler/src/index.ts. Were you able to reproduce the issue with my test repo?

trivikr commented 4 years ago

All AWS SDK v3 packages are exported as ESM in 1.0.0-gamma.3

However, a new error appears with rollup using @aws-sdk/client-sts@1.0.0-gamma.3

@aws-sdk/protocol-http (imported by node_modules/@aws-sdk/client-sts/dist/es/protocols/Aws_query.js)
[!] Error: 'parse' is not exported by node_modules/fast-xml-parser/src/parser.js, imported by node_modules/@aws-sdk/client-sts/dist/es/protocols/Aws_query.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/@aws-sdk/client-sts/dist/es/protocols/Aws_query.js (4:9)

Code in https://github.com/trivikr/js-sdk-v3-rollup/tree/gamma

andrefelipe commented 3 years ago

Also getting the same error when bundling with Rollup. Any ideas on how to fix?

Error: 'parse' is not exported by node_modules/bowser/src/bowser.js, imported by node_modules/@aws-sdk/util-user-agent-browser/dist/es/index.js

monken commented 3 years ago

I've since switched to https://esbuild.github.io/ which can deal with @aws-sdk just fine (and is blazingly fast).

trivikr commented 3 years ago

Revisiting this issue while examining xml-parser issues.

Tested rollup bundling with @aws-sdk/client-sts@3.9.0 in https://github.com/trivikr/js-sdk-v3-rollup/tree/test-3.9.0

The new error is due to v4 from uuid:

Error: 'v4' is not exported by node_modules/uuid/index.js, imported by node_modules/@aws-sdk/middleware-retry/dist/es/defaultStrategy.js
    at error (/Users/trivikr/workspace/js-sdk-v3-rollup/node_modules/rollup/dist/shared/rollup.js:161:30)
    at Module.error (/Users/trivikr/workspace/js-sdk-v3-rollup/node_modules/rollup/dist/shared/rollup.js:15027:16)
thefat32 commented 3 years ago

Error when using @aws-sdk/client-lex-runtime-v2 in my lib and generating bundle using rollup

[build:bundles] [!] Error: 'parse' is not exported by node_modules\fast-xml-parser\src\parser.js, imported by node_modules\@aws-sdk\client-sts\dist\es\protocols\Aws_query.js
[build:bundles] https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
[build:bundles] node_modules\@aws-sdk\client-sts\dist\es\protocols\Aws_query.js (5:9)
[build:bundles] 3: import { expectNonNull as __expectNonNull, expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getValueFromTextNode as __getValueFromTextNode, parseRfc3339DateTime as __parseRf
c3339DateTime, strictParseInt32 as __strictParseInt32, } from "@aws-sdk/smithy-client";
[build:bundles] 4: import { decodeHTML } from "entities";
[build:bundles] 5: import { parse as xmlParse } from "fast-xml-parser";
[build:bundles]             ^
[build:bundles] 6: export var serializeAws_queryAssumeRoleCommand = function (input, context) { return __awaiter(void 0, void 0, void 0, function () {
[build:bundles] 7:     var headers, body;
[build:bundles] Error: 'parse' is not exported by node_modules\fast-xml-parser\src\parser.js, imported by node_modules\@aws-sdk\client-sts\dist\es\protocols\Aws_query.js
tbenbrahim commented 2 years ago

using "@rollup/plugin-node-resolve": "^13.0.5",

src/lambda.ts → dist/debug/lambda.js, dist...
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
node_modules\cronstrue\dist\cronstrue.js
 8:   else
 9:     root["cronstrue"] = factory();
10: })(typeof self !== 'undefined' ? self : this, function() {
                                            ^
11: return /******/ (function(modules) { // webpackBootstrap
12: /******/    // The module cache
[!] Error: 'parse' is not exported by node_modules\fast-xml-parser\src\parser.js, imported by node_modules\@aws-sdk\client-sts\dist\es\protocols\Aws_query.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules\@aws-sdk\client-sts\dist\es\protocols\Aws_query.js (5:9)
github-actions[bot] commented 1 year ago

Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.

github-actions[bot] commented 1 year ago

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.