--import CLI flag (default)
Learn how to use the node --import CLI flag.
The --import
CLI flag in Node is the default way in ESM to preload a module before the application starts. If you cannot use the SDK's default dynamic import behaviour, setting this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the rest of the application runs.
- You're not able to add Node CLI flags or environment variables that are scoped to the function runtime
- Netlify only allows scoped environment variables on its paid plans at this time
- Vercel doesn't currently provide an option for scoping environment variables
If any of those points apply to you, you cannot use the --import
flag to initialize Sentry on the server-side. Check out the guide for using a top-level import or a dynamic import instead.
By default, the SDK will add the Sentry server config to the build output (typically, .output/server/sentry.server.config.mjs
).
After building your Nuxt app with nuxi build
, add the --import
flag followed by the Sentry server config path to the node
command. With the default Nitro Node preset, this typically looks like this:
node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs
Check the log at the very end of the console output after building the application. This will print the node command with the server entry path for your application (node .output/server/index.mjs
with the Node preset). Make sure to update the paths accordingly, especially when using a different Nitro preset.
To make things easier, add a script in the package.json
:
package.json
{
"scripts": {
"start": "node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs"
}
}
To be able to set up Sentry in production, the --import
flag needs to be added wherever you run your application's production build output. Consult your hosting provider's documentation for specific implementation details. Most deployment platforms support this through two primary methods:
node --import .output/server/sentry.server.config.mjs your-server-entry.mjs
NODE_OPTIONS='--import .output/server/sentry.server.config.mjs'
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").