From e836cf860e7d8e3e9e9349475cf61cf63b47128f Mon Sep 17 00:00:00 2001 From: kartikayy007 Date: Thu, 20 Nov 2025 14:45:44 +0530 Subject: [PATCH 1/4] fix: resolve Next.js version mismatch for studio/preview --- src/domains/models/Preview.ts | 14 +++++++++++--- src/domains/models/Studio.ts | 13 +++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/domains/models/Preview.ts b/src/domains/models/Preview.ts index 817e782d3c3..bb421a65238 100644 --- a/src/domains/models/Preview.ts +++ b/src/domains/models/Preview.ts @@ -5,7 +5,6 @@ import { createServer } from 'http'; import { WebSocketServer } from 'ws'; import chokidar from 'chokidar'; import open from 'open'; -import next from 'next'; import path from 'path'; import yaml from 'js-yaml'; import { blueBright, redBright } from 'picocolors'; @@ -24,6 +23,15 @@ function isValidFilePath(filePath: string): boolean { return existsSync(filePath); } +type NextFactory = typeof import('next')['default']; + +function resolveStudioNextInstance(studioPath: string): NextFactory { + const resolvedNextPath = require.resolve('next', { paths: [studioPath] }); + // eslint-disable-next-line @typescript-eslint/no-var-requires,security/detect-non-literal-require + const nextModule = require(resolvedNextPath); + return (nextModule.default ?? nextModule) as NextFactory; +} + // eslint-disable-next-line sonarjs/cognitive-complexity export function startPreview(filePath:string,base:string | undefined,baseDirectory:string | undefined ,xOrigin:boolean | undefined,suppressLogs:boolean|undefined,port: number = DEFAULT_PORT, noBrowser?: boolean):void { if (filePath && !isValidFilePath(filePath)) { @@ -44,7 +52,8 @@ export function startPreview(filePath:string,base:string | undefined,baseDirecto }); const studioPath = path.dirname(require.resolve('@asyncapi/studio/package.json')); - const app = next({ + const nextInstance = resolveStudioNextInstance(studioPath); + const app = nextInstance({ dev: false, dir: studioPath, conf: { @@ -232,4 +241,3 @@ function findPathsToWatchFromSchemaRef(filePath: string,baseDir:string) { } } } - diff --git a/src/domains/models/Studio.ts b/src/domains/models/Studio.ts index 045daed37b0..0b0aba575bd 100644 --- a/src/domains/models/Studio.ts +++ b/src/domains/models/Studio.ts @@ -4,7 +4,6 @@ import { createServer } from 'http'; import { WebSocketServer } from 'ws'; import chokidar from 'chokidar'; import open from 'open'; -import next from 'next'; import path from 'path'; import { version as studioVersion } from '@asyncapi/studio/package.json'; import { blueBright, redBright } from 'picocolors'; @@ -20,6 +19,15 @@ function isValidFilePath(filePath: string): boolean { return existsSync(filePath); } +type NextFactory = typeof import('next')['default']; + +function resolveStudioNextInstance(studioPath: string): NextFactory { + const resolvedNextPath = require.resolve('next', { paths: [studioPath] }); + // eslint-disable-next-line @typescript-eslint/no-var-requires,security/detect-non-literal-require + const nextModule = require(resolvedNextPath); + return (nextModule.default ?? nextModule) as NextFactory; +} + // eslint-disable-next-line sonarjs/cognitive-complexity export function start(filePath: string, port: number = DEFAULT_PORT, noBrowser?:boolean): void { if (filePath && !isValidFilePath(filePath)) { @@ -30,7 +38,8 @@ export function start(filePath: string, port: number = DEFAULT_PORT, noBrowser?: const studioPath = path.dirname( require.resolve('@asyncapi/studio/package.json'), ); - const app = next({ + const nextInstance = resolveStudioNextInstance(studioPath); + const app = nextInstance({ dev: false, dir: studioPath, conf: { From dbf4d1f8473957098a90bb76801e39794013c87b Mon Sep 17 00:00:00 2001 From: asyncapi-bot Date: Thu, 20 Nov 2025 18:05:48 +0000 Subject: [PATCH 2/4] chore: add changeset for PR #1902 --- .changeset/1902.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changeset/1902.md diff --git a/.changeset/1902.md b/.changeset/1902.md new file mode 100644 index 00000000000..1ecb0883b63 --- /dev/null +++ b/.changeset/1902.md @@ -0,0 +1,9 @@ +--- +'@asyncapi/cli': patch +--- + +fix: resolve Next.js version mismatch for studio/preview + +- e836cf8: fix: resolve Next.js version mismatch for studio/preview + + From 617e4b55688009811791841303cfd1036f06664b Mon Sep 17 00:00:00 2001 From: kartikayy007 Date: Thu, 20 Nov 2025 23:49:16 +0530 Subject: [PATCH 3/4] fix: remove unnecessary type assertions in Studio and Preview --- src/domains/models/Preview.ts | 2 +- src/domains/models/Studio.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domains/models/Preview.ts b/src/domains/models/Preview.ts index bb421a65238..1a3122e087b 100644 --- a/src/domains/models/Preview.ts +++ b/src/domains/models/Preview.ts @@ -29,7 +29,7 @@ function resolveStudioNextInstance(studioPath: string): NextFactory { const resolvedNextPath = require.resolve('next', { paths: [studioPath] }); // eslint-disable-next-line @typescript-eslint/no-var-requires,security/detect-non-literal-require const nextModule = require(resolvedNextPath); - return (nextModule.default ?? nextModule) as NextFactory; + return nextModule.default ?? nextModule; } // eslint-disable-next-line sonarjs/cognitive-complexity diff --git a/src/domains/models/Studio.ts b/src/domains/models/Studio.ts index 0b0aba575bd..5f637270ba9 100644 --- a/src/domains/models/Studio.ts +++ b/src/domains/models/Studio.ts @@ -25,7 +25,7 @@ function resolveStudioNextInstance(studioPath: string): NextFactory { const resolvedNextPath = require.resolve('next', { paths: [studioPath] }); // eslint-disable-next-line @typescript-eslint/no-var-requires,security/detect-non-literal-require const nextModule = require(resolvedNextPath); - return (nextModule.default ?? nextModule) as NextFactory; + return nextModule.default ?? nextModule; } // eslint-disable-next-line sonarjs/cognitive-complexity From 2a509a6cae0e4c5904c8a58f3af30b0186923206 Mon Sep 17 00:00:00 2001 From: asyncapi-bot Date: Thu, 20 Nov 2025 18:21:05 +0000 Subject: [PATCH 4/4] chore: add changeset for PR #1902 --- .changeset/1902.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/1902.md b/.changeset/1902.md index 1ecb0883b63..f301a1406fb 100644 --- a/.changeset/1902.md +++ b/.changeset/1902.md @@ -5,5 +5,6 @@ fix: resolve Next.js version mismatch for studio/preview - e836cf8: fix: resolve Next.js version mismatch for studio/preview +- 617e4b5: fix: remove unnecessary type assertions in Studio and Preview