Skip to content

Instantly share code, notes, and snippets.

@BlakeB415
Created June 1, 2022 04:17
Show Gist options
  • Save BlakeB415/a8611bcd90994bdd9702bffcecff1dfc to your computer and use it in GitHub Desktop.
Save BlakeB415/a8611bcd90994bdd9702bffcecff1dfc to your computer and use it in GitHub Desktop.
Patch file for @sentry/node on Nuxt 3
diff --git a/node_modules/@sentry/node/esm/integrations/http.js b/node_modules/@sentry/node/esm/integrations/http.js
index 3fe1317..c8fc3ef 100644
--- a/node_modules/@sentry/node/esm/integrations/http.js
+++ b/node_modules/@sentry/node/esm/integrations/http.js
@@ -3,7 +3,16 @@ import { getCurrentHub } from '@sentry/core';
import { fill, logger, parseSemver } from '@sentry/utils';
import { IS_DEBUG_BUILD } from '../flags';
import { cleanSpanDescription, extractUrl, isSentryRequest, normalizeRequestArgs, } from './utils/http';
+
var NODE_VERSION = parseSemver(process.versions.node);
+
+var httpModule = (await import('http')).default;
+
+var httpsModule;
+if (NODE_VERSION.major && NODE_VERSION.major > 8) {
+ httpsModule = (await import('https')).default;
+}
+
/** http module integration */
var Http = /** @class */ (function () {
/**
@@ -28,15 +37,14 @@ var Http = /** @class */ (function () {
}
var wrappedHandlerMaker = _createWrappedRequestMethodFactory(this._breadcrumbs, this._tracing);
// eslint-disable-next-line @typescript-eslint/no-var-requires
- var httpModule = require('http');
- fill(httpModule, 'get', wrappedHandlerMaker);
- fill(httpModule, 'request', wrappedHandlerMaker);
+ fill(httpModule, 'get', wrappedHandlerMaker);
+ fill(httpModule, 'request', wrappedHandlerMaker);
+
// NOTE: Prior to Node 9, `https` used internals of `http` module, thus we don't patch it.
// If we do, we'd get double breadcrumbs and double spans for `https` calls.
// It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
- if (NODE_VERSION.major && NODE_VERSION.major > 8) {
+ if (NODE_VERSION.major && NODE_VERSION.major > 8 && httpsModule) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
- var httpsModule = require('https');
fill(httpsModule, 'get', wrappedHandlerMaker);
fill(httpsModule, 'request', wrappedHandlerMaker);
}
diff --git a/node_modules/@sentry/node/esm/stack-parser.js b/node_modules/@sentry/node/esm/stack-parser.js
index 8de04a7..6ee2b2b 100644
--- a/node_modules/@sentry/node/esm/stack-parser.js
+++ b/node_modules/@sentry/node/esm/stack-parser.js
@@ -5,7 +5,7 @@ function getModule(filename) {
return;
}
// We could use optional chaining here but webpack does like that mixed with require
- var base = ((require && require.main && require.main.filename && dirname(require.main.filename)) || global.process.cwd()) + "/";
+ var base = (global.process.cwd()) + "/";
// It's specifically a module
var file = basename(filename, '.js');
var path = dirname(filename);
@BlakeB415
Copy link
Author

BlakeB415 commented Jun 1, 2022

Makes sure to add tslib to your transpile param in nuxt.config.ts like so

build: {
	transpile: ['tslib']
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment