diff --git a/packages/vite/src/node/server/middlewares/transform.ts b/packages/vite/src/node/server/middlewares/transform.ts index 7b0fb6b1d97979..5c7ec55bd8fb55 100644 --- a/packages/vite/src/node/server/middlewares/transform.ts +++ b/packages/vite/src/node/server/middlewares/transform.ts @@ -205,12 +205,14 @@ export function transformMiddleware( const type = isDirectCSSRequest(url) ? 'css' : 'js' const isDep = DEP_VERSION_RE.test(url) || depsOptimizer?.isOptimizedDepUrl(url) - const filepath = - result.map == null - ? (await server.moduleGraph.getModuleByUrl(url, false))?.file - : undefined - const originalContent = - filepath != null ? await getOriginalContent(filepath) : undefined + let originalContent: string | undefined + if (type === 'js' && result.map == null) { + const filepath = ( + await server.moduleGraph.getModuleByUrl(url, false) + )?.file + originalContent = + filepath != null ? await getOriginalContent(filepath) : undefined + } return send(req, res, result.code, type, { etag: result.etag, // allow browser to cache npm deps! diff --git a/packages/vite/src/node/server/send.ts b/packages/vite/src/node/server/send.ts index c6de7452824665..414fa4fe998175 100644 --- a/packages/vite/src/node/server/send.ts +++ b/packages/vite/src/node/server/send.ts @@ -27,7 +27,7 @@ export interface SendOptions { cacheControl?: string headers?: OutgoingHttpHeaders map?: SourceMap | { mappings: '' } | null - /** only used when map == null (when the fallback sourcemap is used) */ + /** only used when type === 'js' && map == null (when the fallback sourcemap is used) */ originalContent?: string }