fix: replace dynamic import() with require() to fix pkg binary vm.Script error - #14966
Open
shivennn wants to merge 2 commits into
Open
fix: replace dynamic import() with require() to fix pkg binary vm.Script error#14966shivennn wants to merge 2 commits into
shivennn wants to merge 2 commits into
Conversation
added 2 commits
July 31, 2026 01:57
…ipt error When the Amplify CLI is run as a pkg-bundled binary, Node's vm.Script does not set the importModuleDynamically callback. Any dynamic import() call with a runtime-computed path throws ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING, causing 'amplify codegen add --apiId' to fail at the 'Getting API details' step. Replace dynamic import() with require() in execute-provider-utils.ts and get-provider-plugins.ts since all provider plugins are CommonJS modules. Fixes aws-amplify#14942
… pkg binary fix Adds tests to execute-provider-utils and get-provider-plugins to verify that provider plugins are loaded via require() which is compatible with pkg-bundled binaries. Relates to aws-amplify#14942
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause:
The Amplify CLI is distributed as a pkg-bundled native binary (~/.amplify/bin/amplify). Inside pkg's runtime, module execution happens via Node's vm.Script. When vm.Script encounters a dynamic import() call with a runtime-computed path, Node throws ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING because pkg does not set the required importModuleDynamically callback.
Two files were affected:
packages/amplify-cli/src/extensions/amplify-helpers/execute-provider-utils.ts
packages/amplify-cli/src/extensions/amplify-helpers/get-provider-plugins.ts
Fix:
Replace dynamic import() calls with require(). Since all provider plugins (e.g. amplify-provider-awscloudformation) are CommonJS modules, require() is fully compatible and works correctly inside pkg's bundled runtime.
Description of changes
When amplify codegen add --apiId --region is run from a project without amplify init, the CLI fails at the "Getting API details" step with:
Issue #, if available
Fixes #14942
Description of how you validated changes
Built locally using yarn setup-dev and tested against a fresh Create React App project without amplify init:
Before fix:
After fix:
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.