Skip to content

fix: declare tslib ^2.1.0 in datastore-storage-adapter and notifications (__spreadArray) - #14881

Merged
ahmedhamouda78 merged 3 commits into
aws-amplify:v5-stablefrom
ahmedhamouda78:fix/tslib-spreadarray-storage-adapter-notifications
Jul 23, 2026
Merged

fix: declare tslib ^2.1.0 in datastore-storage-adapter and notifications (__spreadArray)#14881
ahmedhamouda78 merged 3 commits into
aws-amplify:v5-stablefrom
ahmedhamouda78:fix/tslib-spreadarray-storage-adapter-notifications

Conversation

@ahmedhamouda78

Copy link
Copy Markdown
Member

Summary

@aws-amplify/datastore-storage-adapter and @aws-amplify/notifications can fail at bundle/runtime with __spreadArray is not a function because their compiled output imports __spreadArray from tslib but neither package declares a tslib dependency — so a consumer can resolve an incompatible tslib (< 2.1). This declares tslib ^2.1.0 in both.

This is the same class of bug as #14865 (fixed for @aws-amplify/datastore in #14878). These two packages share datastore's exact profile.

Root cause

Both packages build via node ./buildtsconfig.build.jsonpackages/tsconfig.base.json, which sets target: es5 + downlevelIteration: true + importHelpers: true. So their emitted lib//lib-esm/ import TypeScript helpers from tslib, including tslib.__spreadArray — which only exists in tslib ≥ 2.1.0 (it is absent in tslib 1.x and 2.0.x). Neither package declares any tslib dependency, so a consumer's tree can resolve their tslib import to 1.x (e.g. pulled in by a peer such as apollo-boost), giving __spreadArray is not a function.

Example from the shipped datastore-storage-adapter (lib/common/SQLiteUtils.js):

return tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(acc), false), ['"id" PRIMARY KEY NOT NULL'], false);

The fix

package before after published tslib.__spreadArray refs
@aws-amplify/datastore-storage-adapter (no tslib dependency) tslib: ^2.1.0 19
@aws-amplify/notifications (no tslib dependency) tslib: ^2.1.0 4

^2.1.0 is the exact version that introduced __spreadArray; ^2.0.0 is insufficient because 2.0.x still lacks it. This is consistent with the rest of the monorepo (the aws-amplify meta already depends on tslib ^2.0.0).

Verification

tslib exports (runtime typeof):

tslib __spreadArray
1.14.1 undefined
2.0.3 undefined
2.1.0 / 2.7.0 / 2.8.1 function

Published artifacts import tslib.__spreadArray: datastore-storage-adapter@2.0.70 = 19 refs, notifications@1.6.21 = 4 refs.

End-to-end (real emitted tslib_1.__spreadArray(...) shape, consumer where a peer forces tslib@1.x):

package declares resolves tslib → result
no tslib dep (today) 1.14.1 TypeError: tslib_1.__spreadArray is not a function
tslib ^2.1.0 (this PR) 2.8.1 (own nested copy) ✅ works

Lockfile: yarn install is a no-op for yarn.locktslib@^2.1.0 already resolves to tslib@2.7.0 in the current lock (which has __spreadArray). In the installed workspace, both packages resolve tslib 2.7.0.

Related

…ons (__spreadArray)

@aws-amplify/datastore-storage-adapter and @aws-amplify/notifications are
compiled with target es5 + downlevelIteration + importHelpers: true (via
`node ./build` -> tsconfig.build.json -> tsconfig.base.json), so their emitted
lib/ imports TypeScript helpers from tslib, including tslib.__spreadArray. That
helper only exists in tslib >= 2.1.0. Neither package declares tslib as a
dependency, so a consumer's dependency tree can resolve their tslib import to an
incompatible version (e.g. tslib@1.x from a peer), producing the runtime error
"__spreadArray is not a function".

Same class of bug as aws-amplify#14865 (fixed for @aws-amplify/datastore in aws-amplify#14878); these
two packages share datastore's exact profile (import tslib.__spreadArray, declare
no tslib). Declare tslib ^2.1.0 (the exact version that introduced __spreadArray;
^2.0.0 is insufficient because 2.0.x still lacks it).

Packages fixed:
- @aws-amplify/datastore-storage-adapter (19 imported __spreadArray refs, no tslib dep)
- @aws-amplify/notifications (4 imported __spreadArray refs, no tslib dep)

Verified: __spreadArray is undefined in tslib 1.14.1/2.0.3 and a function from
2.1.0+; published artifacts import tslib.__spreadArray (19 and 4 refs); an
end-to-end consumer where a peer forces tslib@1.x throws "__spreadArray is not a
function" with no tslib dep and works once tslib ^2.1.0 is declared; yarn install
is a no-op for yarn.lock (tslib@^2.1.0 already resolves to 2.7.0).

Related: aws-amplify#14865, aws-amplify#14878
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 50f5282

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ahmedhamouda78
ahmedhamouda78 marked this pull request as ready for review July 20, 2026 14:53
@ahmedhamouda78
ahmedhamouda78 requested review from a team as code owners July 20, 2026 14:53
@ahmedhamouda78
ahmedhamouda78 merged commit be16c37 into aws-amplify:v5-stable Jul 23, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants