Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure NODE_OPTIONS environment variable on amplify hosting runtime to use node option --enable-source-maps #3990

Open
3 tasks done
gecko655 opened this issue Jan 31, 2025 · 1 comment
Labels
feature-request New feature or request

Comments

@gecko655
Copy link

Before opening, please confirm:

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:

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:

{
  "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.

{
  "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.

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:

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.

@gecko655 gecko655 added the feature-request New feature or request label Jan 31, 2025
Copy link

This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant