close
Skip to content

fix: Reorder extension resolution to prioritise TypeScript over JSON#1315

Open
PierreVanobbergen wants to merge 1 commit intovercel:mainfrom
PierreVanobbergen:main
Open

fix: Reorder extension resolution to prioritise TypeScript over JSON#1315
PierreVanobbergen wants to merge 1 commit intovercel:mainfrom
PierreVanobbergen:main

Conversation

@PierreVanobbergen
Copy link
Copy Markdown

@PierreVanobbergen PierreVanobbergen commented Apr 23, 2026

When a directory contains both test.json and test.ts, an extensionless import like:

import { myFunction } from './test';

resolves to test.json instead of test.ts, causing all exported methods from the TypeScript file to be unresolvable during the build.

Webpack resolves extensions in the order they appear in the resolve.extensions array.

Since .json appears before .ts and .tsx, webpack picks the JSON file first when both exist.

Reproduce

(The test project need a tsconfig.json with compilerOptions.resolveJsonModule: true)

  1. Create a directory with two files sharing the same base name:

    src/test.json

    { "key": "value" }

    src/test.ts

    export function greet(): string {
      return "hello";
    }
  2. Import without an extension from another TypeScript file:

    src/index.ts

    import { greet } from './test';
    console.log(greet());
  3. Run ncc build src/index.ts the build fails because ./test resolves to test.json, which has no greet export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant