Skip to content

build: stub optional aws-crt/aws-sdk to remove webpack build warnings#1141

Open
matthewhanson wants to merge 1 commit into
mainfrom
fix/aws-crt-webpack-596
Open

build: stub optional aws-crt/aws-sdk to remove webpack build warnings#1141
matthewhanson wants to merge 1 commit into
mainfrom
fix/aws-crt-webpack-596

Conversation

@matthewhanson

Copy link
Copy Markdown
Member

Summary

Closes #596. The build emitted Module not found: Can't resolve 'aws-crt' (and, after the AWS SDK v3 updates, the equivalent Can't resolve 'aws-sdk' from the OpenSearch client's AwsSigv4Signer) — optional dependencies that stac-server never uses at runtime.

Change

Add resolve.fallback: { 'aws-crt': false, 'aws-sdk': false } to all five lambda webpack configs (api, ingest, pre-hook, post-hook, and the lambda-dist bundle). webpack then resolves these optional modules to empty instead of warning.

Safe because:

  • aws-crt is an optional native dep the SDK probes for and gracefully does without.
  • aws-sdk (v2) is only used by AwsSigv4Signer when no getCredentials is supplied — stac-server always supplies a v3 defaultProvider() (database-client.ts), so that path is dead code.

Verification

npm run build goes from 2 warnings to 1 — the aws-sdk/aws-crt "Can't resolve" warning is gone (aws-sdk (ignored)). The two remaining warnings (express/lib/view.js, keyv/src/index.js) are unrelated benign dynamic-require internals, out of scope for this issue.

Closes #596

🤖 Generated with Claude Code

stac-server builds emitted "Module not found: Can't resolve" warnings for
optional AWS SDK deps that are never used at runtime: `aws-crt` (an optional
native dependency) and `aws-sdk` v2 (the OpenSearch AwsSigv4Signer's fallback
credential path — stac-server always supplies a v3 `getCredentials`). Stub
both via `resolve.fallback` in every lambda webpack config so the build is
clean.

Closes #596.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses noisy webpack build warnings caused by optional AWS-related dependencies (aws-crt and aws-sdk v2) that are referenced by upstream libraries but not used by stac-server at runtime, by updating the lambda webpack configs to prevent webpack from emitting “Can’t resolve …” warnings.

Changes:

  • Add resolve.fallback entries for aws-crt and aws-sdk across all lambda webpack configs to suppress missing-module warnings.
  • Document the warning removal in CHANGELOG.md.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/lambdas/webpack.config.js Adds resolve.fallback for optional AWS modules in the lambda-dist bundle config.
src/lambdas/api/webpack.config.js Adds resolve.fallback for optional AWS modules in the API lambda bundle config.
src/lambdas/ingest/webpack.config.js Adds resolve.fallback for optional AWS modules in the ingest lambda bundle config.
src/lambdas/pre-hook/webpack.config.js Adds resolve.fallback for optional AWS modules in the pre-hook lambda bundle config.
src/lambdas/post-hook/webpack.config.js Adds resolve.fallback for optional AWS modules in the post-hook lambda bundle config.
CHANGELOG.md Notes the removal of the “Can’t resolve” warnings via webpack config updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

devtool,
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],
fallback: { 'aws-crt': false, 'aws-sdk': false },
devtool,
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],
fallback: { 'aws-crt': false, 'aws-sdk': false },
devtool,
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],
fallback: { 'aws-crt': false, 'aws-sdk': false },
devtool,
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],
fallback: { 'aws-crt': false, 'aws-sdk': false },
devtool,
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],
fallback: { 'aws-crt': false, 'aws-sdk': false },
@matthewhanson

Copy link
Copy Markdown
Member Author

Re: the review note that resolve.fallback: { x: false } resolves to an empty stub rather than a true "module not found" — valid in general, but it's a no-op for stac-server's actual usage, so I'm keeping the simpler fallback approach:

  • aws-sdk: the OpenSearch AwsSigv4Signer reads it via a guarded await import('aws-sdk') in a try/catch, then checks awsV2.default && typeof awsV2.default.config.getCredentials === 'function'. With the empty stub, .default is undefined, so the check is false and it's correctly treated as unavailable — no false positive. And that v2 fallback only runs when no getCredentials is supplied; database-client.ts always passes getCredentials: () => defaultProvider()(), so the path is dead code regardless.
  • aws-crt: not actually referenced by the current dependency tree (the literal aws-crt warning was already resolved by the AWS SDK v3 bumps); the entry is defensive only.

So there's no runtime-semantics change in practice. Switching to externals (a true runtime require that throws) would also work since both probes are in try/catch, but it's finickier with the dynamic import() and buys nothing here. Happy to revisit if a future dep actually probes aws-crt/aws-sdk unguarded.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

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.

Can't resolve 'aws-crt'

2 participants