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

Error [ERR_INSPECTOR_NOT_AVAILABLE]: Inspector is not available when using vercel/pkg #6769

Closed
3 tasks done
zolbooo opened this issue Jan 13, 2023 · 7 comments · Fixed by #6780
Closed
3 tasks done

Comments

@zolbooo
Copy link

zolbooo commented Jan 13, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/angular

SDK Version

7.30.0

Framework Version

No response

Link to Sentry event

No response

Steps to Reproduce

The new LocalVariables integration (#6478) causes pkg-bundled app to crash. Is there a way to disable this integration?

  1. Build app with Sentry SDK 7.30.0 using pkg
  2. Run app and experience crash

Expected Result

App should not crash

Actual Result

Error [ERR_INSPECTOR_NOT_AVAILABLE]: Inspector is not available
    at new NodeError (node:internal/errors:388:5)
    at node:inspector:23:9
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:329:7)
    at NativeModule.compileForPublicLoader (node:internal/bootstrap/loaders:269:10)
    at loadNativeModule (node:internal/modules/cjs/helpers:49:9)
    at Module._load (node:internal/modules/cjs/loader:813:15)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at Module.require (pkg/prelude/bootstrap.js:1855:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/snapshot/app/node_modules/@sentry/node/cjs/integrations/localvariables.js:7:19)
@lforst
Copy link
Member

lforst commented Jan 13, 2023

Hi, docs on how to remove integrations can be found here: https://docs.sentry.io/platforms/javascript/configuration/integrations/default/#removing-an-integration

@zolbooo
Copy link
Author

zolbooo commented Jan 13, 2023

Thank you, I will try this out.

Yet still, I don't think that it's an intended behavior, this could be a breaking change for environments without inspector available (such as pkg-based apps).

UPD: Should I provide a repro?

@zolbooo
Copy link
Author

zolbooo commented Jan 14, 2023

Hi, docs on how to remove integrations can be found here: https://docs.sentry.io/platforms/javascript/configuration/integrations/default/#removing-an-integration

I tried your solution, but app still crashes. It's because error is thrown when require-ing node_modules/@sentry/node/cjs/integrations/localvariables.js, so filtering out an integration won't help.

@lforst
Copy link
Member

lforst commented Jan 15, 2023

Hi, docs on how to remove integrations can be found here: docs.sentry.io/platforms/javascript/configuration/integrations/default/#removing-an-integration

I tried your solution, but app still crashes. It's because error is thrown when require-ing node_modules/@sentry/node/cjs/integrations/localvariables.js, so filtering out an integration won't help.

Got it. I see the problem. The pkg use case seems a bit niche to me personally. I am gonna take this to the team to discuss. There are definitely ways for you to get around this: tree shaking comes to mind.

Personally, I can't think of a way right now to solve your problem from the SDK side of things. Do you have ideas or recommendations?

@zolbooo
Copy link
Author

zolbooo commented Jan 15, 2023

Yes, I think it's such quite a rare edge case.

Also I recommend to check available builtin modules and process config, something like:

require('node:module').builtinModules.includes('inspector')
process.config.variables.v8_enable_inspector // 1 when enabled, 0 otherwise

I have ran some checks with following example script:

console.log(require('node:module').builtinModules.includes('inspector'));
console.log(process.config.variables.v8_enable_inspector);
require('inspector');

Here is the terminal output:

$ node builtin-check.js
true
1
$ pkg builtin-check.js && ./builtin-check-macos
> pkg@5.8.0
> Targets not specified. Assuming:
  node16-linux-arm64, node16-macos-arm64, node16-win-arm64
true
0
pkg/prelude/bootstrap.js:1876
      throw error;
      ^

Error [ERR_INSPECTOR_NOT_AVAILABLE]: Inspector is not available
    at new NodeError (node:internal/errors:372:5)
    at node:inspector:23:9
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:312:7)
    at NativeModule.compileForPublicLoader (node:internal/bootstrap/loaders:252:10)
    at loadNativeModule (node:internal/modules/cjs/helpers:49:9)
    at Function.Module._load (node:internal/modules/cjs/loader:804:15)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module.require (pkg/prelude/bootstrap.js:1855:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/snapshot/test/builtin-check.js) {
  code: 'ERR_INSPECTOR_NOT_AVAILABLE'
}

I used https://github.com/standard-things/esm/blob/master/src/env/has-inspector.js for a reference.

@zolbooo
Copy link
Author

zolbooo commented Jan 16, 2023

Here is the patch file for patch-package in case if somebody uses pkg: patches/@sentry+node+7.30.0.patch

diff --git a/node_modules/@sentry/node/cjs/integrations/index.js b/node_modules/@sentry/node/cjs/integrations/index.js
index 6e9c01e..faf4c78 100644
--- a/node_modules/@sentry/node/cjs/integrations/index.js
+++ b/node_modules/@sentry/node/cjs/integrations/index.js
@@ -9,9 +9,11 @@ const modules = require('./modules.js');
 const contextlines = require('./contextlines.js');
 const context = require('./context.js');
 const requestdata = require('./requestdata.js');
-const localvariables = require('./localvariables.js');
-
 
+if (process.config.variables.v8_enable_inspector === 1) {
+	const localvariables = require('./localvariables.js');
+	exports.LocalVariables = localvariables.LocalVariables;
+}
 
 exports.Console = console.Console;
 exports.Http = http.Http;
@@ -22,5 +24,4 @@ exports.Modules = modules.Modules;
 exports.ContextLines = contextlines.ContextLines;
 exports.Context = context.Context;
 exports.RequestData = requestdata.RequestData;
-exports.LocalVariables = localvariables.LocalVariables;
 //# sourceMappingURL=index.js.map
diff --git a/node_modules/@sentry/node/cjs/sdk.js b/node_modules/@sentry/node/cjs/sdk.js
index 6749e06..fddc50f 100644
--- a/node_modules/@sentry/node/cjs/sdk.js
+++ b/node_modules/@sentry/node/cjs/sdk.js
@@ -16,7 +16,6 @@ const http = require('./integrations/http.js');
 const onuncaughtexception = require('./integrations/onuncaughtexception.js');
 const onunhandledrejection = require('./integrations/onunhandledrejection.js');
 const contextlines = require('./integrations/contextlines.js');
-const localvariables = require('./integrations/localvariables.js');
 const context = require('./integrations/context.js');
 const modules = require('./integrations/modules.js');
 const requestdata = require('./integrations/requestdata.js');
@@ -37,7 +36,6 @@ const defaultIntegrations = [
   new onunhandledrejection.OnUnhandledRejection(),
   // Event Info
   new contextlines.ContextLines(),
-  new localvariables.LocalVariables(),
   new context.Context(),
   new modules.Modules(),
   new requestdata.RequestData(),
@@ -45,6 +43,11 @@ const defaultIntegrations = [
   new linkederrors.LinkedErrors(),
 ];
 
+if (process.config.variables.v8_enable_inspector === 1) {
+  const localvariables = require('./integrations/localvariables.js');
+  defaultIntegrations.push(new localvariables.LocalVariables());
+}
+
 /**
  * The Sentry Node SDK Client.
  *

@AbhiPrasad
Copy link
Member

@zolbooo This is fixed in the latest release - https://github.com/getsentry/sentry-javascript/releases/tag/7.31.0. Thanks for reporting the bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants