Skip to content

Commit a10cc10

Browse files
authored
ref(nextjs): Drop resolve dependency (#18618)
### Summary Removes `resolve` dependency and replaces it with `createRequire` which would work in esm modules as well, since our min Node.js version is 18 then it should be fine to do this replacement. This should reduce the npm install size and the SSR bundle size for the SDK. closes #12860
1 parent 9ecd7f5 commit a10cc10

File tree

5 files changed

+6
-20
lines changed

5 files changed

+6
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

7+
- ref(nextjs): Drop `resolve` dependency from the Next.js SDK ([#18618](https://github.com/getsentry/sentry-javascript/pull/18618))
8+
79
## 10.32.1
810

911
- fix(cloudflare): Add hono transaction name when error is thrown ([#18529](https://github.com/getsentry/sentry-javascript/pull/18529))

packages/nextjs/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,10 @@
8787
"@sentry/react": "10.32.1",
8888
"@sentry/vercel-edge": "10.32.1",
8989
"@sentry/webpack-plugin": "^4.6.1",
90-
"resolve": "1.22.8",
9190
"rollup": "^4.35.0",
9291
"stacktrace-parser": "^0.1.10"
9392
},
9493
"devDependencies": {
95-
"@types/resolve": "1.20.3",
9694
"eslint-plugin-react": "^7.31.11",
9795
"next": "13.5.9",
9896
"react": "^18.3.1",

packages/nextjs/src/config/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parseSemver } from '@sentry/core';
22
import * as fs from 'fs';
3-
import { sync as resolveSync } from 'resolve';
3+
import { createRequire } from 'module';
44

55
/**
66
* Returns the version of Next.js installed in the project, or undefined if it cannot be determined.
@@ -23,7 +23,7 @@ export function getNextjsVersion(): string | undefined {
2323

2424
function resolveNextjsPackageJson(): string | undefined {
2525
try {
26-
return resolveSync('next/package.json', { basedir: process.cwd() });
26+
return createRequire(`${process.cwd()}/`).resolve('next/package.json');
2727
} catch {
2828
return undefined;
2929
}

packages/nextjs/src/config/webpack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import { debug, escapeStringForRegex, loadModule, parseSemver } from '@sentry/core';
55
import * as fs from 'fs';
6+
import { createRequire } from 'module';
67
import * as path from 'path';
7-
import { sync as resolveSync } from 'resolve';
88
import type { VercelCronsConfig } from '../common/types';
99
import { getBuildPluginOptions, normalizePathForGlob } from './getBuildPluginOptions';
1010
import type { RouteManifest } from './manifest/types';
@@ -790,7 +790,7 @@ function addValueInjectionLoader({
790790

791791
function resolveNextPackageDirFromDirectory(basedir: string): string | undefined {
792792
try {
793-
return path.dirname(resolveSync('next/package.json', { basedir }));
793+
return path.dirname(createRequire(`${basedir}/`).resolve('next/package.json'));
794794
} catch {
795795
// Should not happen in theory
796796
return undefined;

yarn.lock

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9069,11 +9069,6 @@
90699069
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
90709070
integrity sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==
90719071

9072-
9073-
version "1.20.3"
9074-
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.3.tgz#066742d69a0bbba8c5d7d517f82e1140ddeb3c3c"
9075-
integrity sha512-NH5oErHOtHZYcjCtg69t26aXEk4BN2zLWqf7wnDZ+dpe0iR7Rds1SPGEItl3fca21oOe0n3OCnZ4W7jBxu7FOw==
9076-
90779072
90789073
version "0.12.0"
90799074
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
@@ -27064,15 +27059,6 @@ [email protected]:
2706427059
path-parse "^1.0.7"
2706527060
supports-preserve-symlinks-flag "^1.0.0"
2706627061

27067-
27068-
version "1.22.8"
27069-
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d"
27070-
integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==
27071-
dependencies:
27072-
is-core-module "^2.13.0"
27073-
path-parse "^1.0.7"
27074-
supports-preserve-symlinks-flag "^1.0.0"
27075-
2707627062
resolve@^1.1.6, resolve@^1.1.7, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.11.1, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.22.0, resolve@^1.22.1, resolve@^1.22.10, resolve@^1.22.4, resolve@^1.22.6, resolve@^1.22.8, resolve@^1.4.0, resolve@^1.5.0:
2707727063
version "1.22.10"
2707827064
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.10.tgz#b663e83ffb09bbf2386944736baae803029b8b39"

0 commit comments

Comments
 (0)