Skip to content

Commit 52da218

Browse files
committed
refactor: wip
1 parent fb078f0 commit 52da218

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
/coverage
44
/.nx
55
__snapshots__
6+
7+
# Test fixtures with intentional syntax errors
8+
packages/utils/mocks/fixtures/actually-invalid.js
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is an actually invalid JavaScript file with syntax errors
2+
const x = {
3+
missing: "closing brace"
4+
// Unclosed object

packages/utils/mocks/fixtures/invalid-js-file.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/utils/src/lib/import-module.int.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ describe('importModule', () => {
5858

5959
it('should throw if file is not valid JS', async () => {
6060
await expect(
61-
importModule({ filepath: path.join(mockDir, 'invalid-js-file.json') }),
62-
).rejects.toThrow(/invalid-js-file\.json/);
61+
importModule({ filepath: path.join(mockDir, 'actually-invalid.js') }),
62+
).rejects.toThrow();
6363
});
6464

6565
it('should load a TS module using tsconfig paths', async () => {

packages/utils/src/lib/import-module.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,14 @@ export async function createTsJiti(
198198
...(jitiOptions.nativeModules ?? []),
199199
]),
200200
],
201-
// Don't use native imports when we have aliases to resolve
202-
// When tryNative is true, jiti attempts to use native Node.js imports first,
203-
// which don't understand path aliases and will fail with ERR_MODULE_NOT_FOUND
204-
tryNative: Object.keys(mergedAlias).length === 0,
201+
// Use tryNative: false by default for consistent, predictable behavior
202+
// Native imports don't support:
203+
// - TypeScript files (.ts)
204+
// - Path aliases from tsconfig
205+
// - Non-standard JavaScript features that jiti can transpile
206+
// Since this is used for config file loading where these features are common,
207+
// it's safer to always let jiti handle the transformation
208+
tryNative: false,
205209
});
206210
}
207211

0 commit comments

Comments
 (0)