aws-amplify / aws-amplify/amplify-hosting
Configure NODE_OPTIONS environment variable on amplify hosting runtime to use node option --enable-source-maps
- Dominant language
- Dockerfile
- Stars
- 481
- Forks
- 123
- PR merge metrics
- No merged PRs in 30d
Description
### Before opening, please confirm:
- [x] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [x] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [x] I have removed any sensitive information from my code snippets and submission.
### Amplify Hosting feature
Environment variables
### Is your feature request related to a problem? Please describe:
#### background
Nodejs has a feature to output logs with source map, showing the stacktrace of source code lines like:
```
Error [SomeError]: Request failed with status code 400
at async c (webpack://some/pre/compiled/source/code/file.ts:51:30)
at async l (webpack://some/pre/compiled/source/code/file.ts:122:19)
```
instead of showing the stacktrace of transpiled & minified source code lines like:
```
Error [SomeError]: Request failed with status code 400
at eP (.next/server/chunks/850.js:21:59036)
at async c (.next/server/chunks/847.js:1:13619)
```
The feature can be turned on if these conditions are met:
**compile the source code with source map**
For example, next.js can compile with source map with the following config:
```next.config.js
const nextConfig = {
// ...
webpack: (config, {isServer}) => {
if (isServer) {
config.devtool = 'source-map'
}
return config
},
}
```
ref: https://www.highlight.io/blog/lw5-next-js-server-sourcemaps
**set NODE_OPTIONS=--enable-source-maps to launch nodejs**
To use source map for server side logging, at this time, the `--enable-source-maps` is needed as the launch option of nodejs.
https://nodejs.org/dist/latest-v22.x/docs/api/cli.html#cli_enable_source_maps
For example, the following next.js package.json can output logs with real source code lines:
```json
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "NODE_OPTIONS=--enable-source-maps next start",
}
// other configs are omitted
}
```
#### problem
The amplify hosting service ignores the `NODE_OPTIONS` runtime environment.
I did the following things:
**adding `NODE_OPTIONS=--enable-source-maps` to the package.json file** does not take effect. Amplify just ignores it.
```json
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "NODE_OPTIONS=--enable-source-maps next start",
}
// other configs are omitted
}
```
**adding `NODE_OPTIONS=--enable-source-maps` to the.env.production while building the source** does not take effect. Amplify just ignores it.
```yml
version: 1
applications:
frontend:
phases:
build:
commands:
- echo 'NODE_OPTIONS=--enable-source-maps' >> .env.production
- yarn build
artifacts:
baseDirectory: .next
files:
- '**/*'
```
### Describe how you'd like this feature to work
I'd like to set (OR append) NODE_OPTIONS option for the amplify hosting runtime.
The feature might look like changing amplify.yml spec as:
```yml
version: 1
applications:
frontend:
phases:
build:
commands:
- (omit)
runtime_node_options:
- '--enable-source-maps'
artifacts:
baseDirectory: .next
files:
- '**/*'
```
But I'd appreciate if the feature is implemented in any kinds of ways.
Contributor guide
Research direction
Start by reviewing the proposed amplify.yml runtime_node_options configuration alongside package.json, .env.production, and next.config.js. Trace how Amplify launches the Node.js runtime and determine how NODE_OPTIONS can be set or appended there. Done means --enable-source-maps is honored at runtime and server logs show source-mapped lines for a configured Next.js deployment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, next.js, node.js
- Domain
- cloud, devops
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100