sentry-javascript-bundler-plugins
sentry-javascript-bundler-plugins copied to clipboard
Cannot find package '_sentry-debug-id-injection-stub'
Environment
MacOS NodeJS with Remix framework and esbuild bundler "@sentry/esbuild-plugin": "^2.10.1"
Steps to Reproduce
- Created Remix project with custom express server
- Build server using this package.json script
"build:server": "tsx ./other/build-server.ts",
Content of ./other/build-server.ts
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
import esbuild from "esbuild";
import fsExtra from "fs-extra";
import { globSync } from "glob";
import path from "path";
import { fileURLToPath } from "url";
const pkg = fsExtra.readJsonSync(path.join(process.cwd(), "package.json"));
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const here = (...s: Array<string>) => path.join(__dirname, ...s);
const globsafe = (s: string) => s.replace(/\\/g, "/");
const allFiles = globSync(globsafe(here("../server/**/*.*")), {
ignore: [
"**/tsconfig.json",
"**/eslint*",
"**/__tests__/**",
"server/dev-server.js",
],
});
const entries = [];
for (const file of allFiles) {
if (/\.(ts|js|tsx|jsx)$/.test(file)) {
entries.push(file);
} else {
const dest = file.replace(here("../server"), here("../server-build"));
fsExtra.ensureDirSync(path.parse(dest).dir);
fsExtra.copySync(file, dest);
console.log(`copied: ${file.replace(`${here("../server")}/`, "")}`);
}
}
console.log("building...");
esbuild
.build({
entryPoints: entries,
outdir: here("../server-build"),
target: [`node${pkg.engines.node}`],
platform: "node",
format: "esm",
sourcemap: true,
plugins: [sentryEsbuildPlugin({
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
sourcemaps: {
assets: here("../server-build"),
},
})],
logLevel: "info",
})
.catch((error: unknown) => {
console.error(error);
process.exit(1);
});
Run server
Expected Result
It should start up the server.
Actual Result
It crashes with
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '_sentry-debug-id-injection-stub' imported from /Users/jansedlon/Work/flixy/flixy/server-build/index.js
Error: Cannot find package '_sentry-debug-id-injection-stub' imported from /Users/jansedlon/Work/flixy/flixy/server-build/index.js
at new NodeError (node:internal/errors:406:5)
at packageResolve (node:internal/modules/esm/resolve:789:9)
at moduleResolve (node:internal/modules/esm/resolve:838:20)
at defaultResolve (node:internal/modules/esm/resolve:1043:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:36)
When i open the main built file, it looks like this
var _global = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
_global.SENTRY_RELEASE = { id: "64f00b429b35b64ee526d71600170c0559d5f64d" };
import "_sentry-debug-id-injection-stub";
import * as OriginalModule from "/Users/jansedlon/Work/flixy/flixy/server/index.ts";
var server_default = OriginalModule.default;
export * from "/Users/jansedlon/Work/flixy/flixy/server/index.ts";
export {
server_default as default
};
//# sourceMappingURL=index.js.map
That line import "_sentry-debug-id-injection-stub"; is not any package that can be installed. From what I understood from the your source code, it should be replaced, but it isn't
Hi, which esbuild version are you using?
@lforst Hi 👋 0.19.6
I unfortunately cannot reproduce. Could you provide a small reproduction repo or stackblitz or similar so we can debug this further? Thanks!
Sure, here's reproduction CodeSandbox
Run it using yarn tsx ./other/build-server.ts
And the see the generated file in server-build/index.js
Hi, I believe this is because we only really support esbuild with bundle: true. We should probably special case builds without bundling somehow.
Yeah, probably 👍 This is quite common use case when using Remix with express server.
I am also encountering this issue. I followed npx @sentry/wizard@latest -i sourcemaps and at no point did it tell me it only supports esbuild with bundling -- it'd be great to have a warning or something.
@seeARMS Fair feedback. I opened a PR to at least log a warning, and we will also update the wizard to warn you about this.