You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Reorder extension resolution to prioritise TypeScript over JSON (#1315)
When a directory contains both `test.json` and `test.ts`, an
extensionless import like:
```ts
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`**
```json
{ "key": "value" }
```
**`src/test.ts`**
```ts
export function greet(): string {
return "hello";
}
```
2. Import without an extension from another TypeScript file:
**`src/index.ts`**
```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.
0 commit comments