diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 8ed135ac2fab..c49afc6e0dc5 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -9,8 +9,9 @@ "engines": { "node": ">=8" }, - "main": "build/cjs/index.js", - "module": "build/esm/index.js", + "main": "build/cjs/index.server.js", + "module": "build/esm/index.server.js", + "browser": "build/esm/index.client.js", "types": "build/types/index.types.d.ts", "publishConfig": { "access": "public" @@ -54,7 +55,7 @@ "build:transpile:watch": "nodemon --ext ts --watch src scripts/buildRollup.ts", "build:types:watch": "tsc -p tsconfig.types.json --watch", "build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build", - "circularDepCheck": "madge --circular src/index.ts && madge --circular src/client/index.ts && madge --circular src/index.types.ts", + "circularDepCheck": "madge --circular src/index.client.ts && madge --circular src/edge/index.ts && madge --circular src/index.server.ts && madge --circular src/index.types.ts", "clean": "rimraf build coverage sentry-nextjs-*.tgz", "fix": "run-s fix:eslint fix:prettier", "fix:eslint": "eslint . --format stylish --fix", diff --git a/packages/nextjs/rollup.npm.config.js b/packages/nextjs/rollup.npm.config.js index 5ef6e1ac96a6..27a8dbf7ec9e 100644 --- a/packages/nextjs/rollup.npm.config.js +++ b/packages/nextjs/rollup.npm.config.js @@ -5,7 +5,7 @@ export default [ makeBaseNPMConfig({ // We need to include `instrumentServer.ts` separately because it's only conditionally required, and so rollup // doesn't automatically include it when calculating the module dependency tree. - entrypoints: ['src/index.ts', 'src/client/index.ts', 'src/edge/index.ts', 'src/config/webpack.ts'], + entrypoints: ['src/index.server.ts', 'src/index.client.ts', 'src/edge/index.ts', 'src/config/webpack.ts'], // prevent this internal nextjs code from ending up in our built package (this doesn't happen automatially because // the name doesn't match an SDK dependency) diff --git a/packages/nextjs/src/index.client.ts b/packages/nextjs/src/index.client.ts new file mode 100644 index 000000000000..e7ad6a8700be --- /dev/null +++ b/packages/nextjs/src/index.client.ts @@ -0,0 +1,6 @@ +export * from './client'; + +// This file is the main entrypoint for non-Next.js build pipelines that use +// the package.json's "browser" field or the Edge runtime (Edge API routes and middleware) + +// __SENTRY_SDK_MULTIPLEXER__ diff --git a/packages/nextjs/src/index.server.ts b/packages/nextjs/src/index.server.ts new file mode 100644 index 000000000000..630f45ec6953 --- /dev/null +++ b/packages/nextjs/src/index.server.ts @@ -0,0 +1,6 @@ +export * from './config'; +export * from './server'; + +// This file is the main entrypoint on the server and/or when the package is `require`d + +// __SENTRY_SDK_MULTIPLEXER__ diff --git a/packages/nextjs/src/index.ts b/packages/nextjs/src/index.ts deleted file mode 100644 index 4133c06089d5..000000000000 --- a/packages/nextjs/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './config'; -export * from './server'; - -// __SENTRY_SDK_MULTIPLEXER__ diff --git a/packages/nextjs/test/serverSdk.test.ts b/packages/nextjs/test/serverSdk.test.ts index 1a32551317e5..21fc17dfe185 100644 --- a/packages/nextjs/test/serverSdk.test.ts +++ b/packages/nextjs/test/serverSdk.test.ts @@ -4,7 +4,7 @@ import type { Integration } from '@sentry/types'; import { GLOBAL_OBJ, logger } from '@sentry/utils'; import * as domain from 'domain'; -import { init } from '../src/index'; +import { init } from '../src/server'; const { Integrations } = SentryNode;