Skip to content

Commit

Permalink
no extension to js as well
Browse files Browse the repository at this point in the history
  • Loading branch information
devjiwonchoi committed Nov 1, 2024
1 parent dea7b5a commit 098f4ce
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/next/src/build/next-config-ts/loader.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ export async function resolve(

// From here the specifier will be a relative path.
const ext = extname(specifier)
// If the specifier is "./foo", we try to resolve it as "./foo.ts".
// If the specifier has no extension, we try to resolve it as TS then JS.
if (ext === '') {
const possibleTsFileURL = new URL(url + '.ts', context.parentURL)
const possibleTsFileURL = new URL(specifier + '.ts', context.parentURL)
const possibleJsFileURL = new URL(specifier + '.js', context.parentURL)

if (existsSync(possibleTsFileURL)) {
return {
format: 'typescript',
shortCircuit: true,
url: possibleTsFileURL.href,
}
} else if (existsSync(possibleJsFileURL)) {
return nextResolve(specifier + '.js', context)
} else {
return nextResolve(specifier, context)
}
Expand Down

0 comments on commit 098f4ce

Please sign in to comment.