aws / aws/amazon-cloudfront-client-routing-library
SyntaxError: Cannot use import statement outside a module when deploying/running code related to CloudFront
- Dominant language
- Rust
- Stars
- 14
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
```c
.... .... .1.. = Reset: Set
[Expert Info (Warning/Sequence): Connection reset (RST)]
```
```js
# npm audit report
aws-cdk-lib <=2.189.0
AWS CDK CodePipeline: trusted entities are too broad - https://github.com/advisories/GHSA-5pq3-h73f-66hr
aws-cdk-lib's aspect order change causes different Permissions Boundary assigned to Role - https://github.com/advisories/GHSA-qc59-cxj2-c2w4
fix available via `npm audit fix`
node_modules/aws-cdk-lib
1 low severity vulnerability
To address all issues, run:
npm audit fix
```
```rs
Exception has occurred: Error: command failed
at promiseSpawn (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:22:22)
at spawnWithShell (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:124:10)
at promiseSpawn (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:12:12)
at runScriptPkg (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script-pkg.js:77:13)
at runScript (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script.js:9:12)
at #run (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/lib/commands/run-script.js:130:13)
at async RunScript.exec (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/lib/commands/run-script.js:39:7)
at async Npm.exec (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/lib/npm.js:207:9)
at async module.exports (/usr/local/share/nvm/versions/node/v20.19.0/lib/node_modules/npm/lib/cli/entry.js:74:5)
```
# AWS CloudFront (Likely related to Lambda@Edge or a custom origin that involves Node.js)

Local Development: Linux-based development environment.
Deployment Context: Lambda@Edge function triggered by a CloudFront event...custom origin server running Node.js that CloudFront interacts with.
应用程序遇到“语法错误:无法在模块外使用 `import` 语句”。此 `JavaScript` 错误表明 `import` 关键字正在 ECMAScript 模块不受支持或未明确启用的上下文中使用。这种情况通常发生在运行在 CommonJS 环境中使用 `import` 语法的代码时(除非明确配置为模块,否则 CommonJS 是 Node.js 的默认环境)。
Based on the call stack, the error originates within code related to the promise-spawn module, which is being used by `@smithy/smithy-client`. This suggests that the AWS SDK for JavaScript (v3), specifically the Smithy client, is involved in the CloudFront interaction.
再現手順:
Lambda@Edge 関数を CloudFront ディストリビューションにデプロイします。この関数は、AWS SDK for JavaScript (v3) と @smithy/smithy-client パッケージを使用している可能性があります。
Lambda@Edge 関数が特定の CloudFront イベント(例:ビューワーリクエスト、オリジンリクエスト)でトリガーされるように設定します。
Lambda@Edge 関数をトリガーするリクエストを CloudFront ディストリビューションに送信します。
または、カスタムオリジンサーバーを使用している場合は、AWS SDK (v3) を使用し、CloudFront からアクセスする Node.js アプリケーションをデプロイします。オリジンサーバー上で問題のあるコードを実行するリクエストを CloudFront に送信します。
Lambda@Edge 関数の CloudWatch ログまたはカスタムオリジンサーバーのログでエラーを確認します。
Observed Behavior:
The Lambda@Edge function (custom origin server) fails to execute, throwing a `SyntaxError: Cannot use import statement outside a module`. This likely results in an error response being returned by CloudFront to the client.
Expected Behavior:
The Lambda@Edge function or the custom origin server should execute successfully, interacting with other AWS services (likely through the AWS SDK) as intended, without encountering JavaScript syntax errors.
Contributor guide
Research direction
No repository file or test is identified. Start by reproducing the reported Lambda@Edge or custom-origin deployment with the JavaScript AWS SDK, then inspect the npm command, promise-spawn stack, and @smithy/smithy-client context shown. Done means the deployed function or server runs without the import syntax error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript, node.js
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100