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

Cannot find package '_sentry-debug-id-injection-stub' #445

Open
jansedlon opened this issue Nov 17, 2023 · 8 comments
Open

Cannot find package '_sentry-debug-id-injection-stub' #445

jansedlon opened this issue Nov 17, 2023 · 8 comments
Assignees

Comments

@jansedlon
Copy link

Environment

MacOS
NodeJS with Remix framework and esbuild bundler
"@sentry/esbuild-plugin": "^2.10.1"

Steps to Reproduce

  1. Created Remix project with custom express server
  2. 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

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 17, 2023
@lforst
Copy link
Member

lforst commented Nov 20, 2023

Hi, which esbuild version are you using?

@jansedlon
Copy link
Author

@lforst Hi 👋 0.19.6

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 20, 2023
@lforst
Copy link
Member

lforst commented Nov 20, 2023

I unfortunately cannot reproduce. Could you provide a small reproduction repo or stackblitz or similar so we can debug this further? Thanks!

@jansedlon
Copy link
Author

jansedlon commented Nov 20, 2023

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

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 20, 2023
@lforst
Copy link
Member

lforst commented Nov 21, 2023

Hi, I believe this is because we only really support esbuild with bundle: true. We should probably special case builds without bundling somehow.

@getsantry getsantry bot removed the status in GitHub Issues with 👀 Nov 21, 2023
@lforst lforst self-assigned this Nov 22, 2023
@jansedlon
Copy link
Author

Yeah, probably 👍 This is quite common use case when using Remix with express server.

@seeARMS
Copy link

seeARMS commented Apr 17, 2024

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.

@lforst
Copy link
Member

lforst commented Apr 17, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Status: No status
Development

No branches or pull requests

3 participants