Hi,
I have a project with react router v7 as framework where I want to integrate sentry.
For that, I need to add a instrument.server.mjs
file in the root of the Netlify function with this code:
import * as Sentry from "@sentry/react-router";
Sentry.init({
dsn: "https:xxx",
sendDefaultPii: true,
});
In order to have that file in the function, I need to have this in my netlify.toml
:
[functions]
included_files = ["instrument.server.mjs"]
Then, I added the following env variable to the Netlify function so that it can start the instrument.server.mjs
where Sentry is initialized:
NODE_OPTIONS="--import ./instrument.server.mjs"
I have the issue that in the initializing step during build, I get this error because of the Sentry import:
5:19:30 PM: See https://github.com/jdx/mise/discussions/4345 for more information.
5:19:31 PM: Started restoring cached Node.js version
5:19:32 PM: Finished restoring cached Node.js version
5:19:32 PM: Attempting Node.js version '22.5.1' from .nvmrc
5:19:33 PM: v22.5.1 is already installed.
5:19:33 PM: Now using node v22.5.1
5:19:33 PM: Enabling Node.js Corepack
5:19:33 PM: node:internal/modules/esm/resolve:842
5:19:33 PM: throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
5:19:33 PM: ^
5:19:33 PM: Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sentry/react-router' imported from /opt/build/repo/instrument.server.mjs
5:19:33 PM: at packageResolve (node:internal/modules/esm/resolve:842:9)
5:19:33 PM: at moduleResolve (node:internal/modules/esm/resolve:915:18)
5:19:33 PM: at defaultResolve (node:internal/modules/esm/resolve:1124:11)
5:19:33 PM: at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
5:19:33 PM: at ModuleLoader.resolve (node:internal/modules/esm/loader:526:25)
5:19:33 PM: at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
5:19:33 PM: at ModuleJob._link (node:internal/modules/esm/module_job:126:49) {
5:19:33 PM: code: 'ERR_MODULE_NOT_FOUND'
5:19:33 PM: }
5:19:33 PM: Node.js v22.5.1
How can I add the Sentry dependency to the initialization command?
Or how can I modify the react router start command from Netlify to set the NODE_OPTIONS
env variable only on the start
and build
commands?