Skip to content

Commit

Permalink
fix(ssr): resolve .cjs modules, never resolve .ts/.tsx modules
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 13, 2021
1 parent b2813d5 commit 44123a7
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,6 @@ async function instantiateModule(
root
} = server.config

const extensions = ['.js', '.mjs', '.ts', '.jsx', '.tsx', '.json']

// If an extension is added/removed from DEFAULT_EXTENSIONS, so too
// should it be added/removed from our extensions array. To be sure,
// we verify this when running tests.
if (typeof jest !== 'undefined')
for (const ext of DEFAULT_EXTENSIONS) {
if (!extensions.includes(ext))
throw new Error(
`The module extensions used in SSR should include all DEFAULT_EXTENSIONS`
)
}

// The `extensions` and `mainFields` options are used to ensure that
// CommonJS modules are preferred. We want to avoid ESM->ESM imports
// whenever possible, because `hookNodeResolve` can't intercept them.
Expand All @@ -124,7 +111,7 @@ async function instantiateModule(
// before "import" condition.
conditions: ['node', 'require'],
dedupe,
extensions,
extensions: ['.js', '.cjs', '.mjs', '.jsx', '.json'],
isBuild: true,
isProduction,
mainFields: ['main', ...DEFAULT_MAIN_FIELDS],
Expand Down

0 comments on commit 44123a7

Please sign in to comment.