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
I was getting errors like these when running scripts with `exec scriptName`:
2
+
3
+
```
4
+
7:08:58 PM [vite] Pre-transform error: Failed to load url /api/src/lib/db.js (resolved id: /api/src/lib/db.js) in /Users/tobbe/tmp/cedar-0140-jobs/api/src/lib/jobs.ts. Does the file exist?
5
+
7:08:58 PM [vite] Pre-transform error: Failed to load url /api/src/lib/logger.js (resolved id: /api/src/lib/logger.js) in /Users/tobbe/tmp/cedar-0140-jobs/api/src/lib/jobs.ts. Does the file exist?
6
+
7:08:58 PM [vite] Pre-transform error: Failed to load url /api/src/lib/db.js (resolved id: /api/src/lib/db.js) in /Users/tobbe/tmp/cedar-0140-jobs/api/src/lib/jobs.ts. Does the file exist?
7
+
7:08:58 PM [vite] Pre-transform error: Failed to load url /api/src/lib/logger.js (resolved id: /api/src/lib/logger.js) in /Users/tobbe/tmp/cedar-0140-jobs/api/src/lib/jobs.ts. Does the file exist?
8
+
```
9
+
10
+
The issue is with these imports:
11
+
12
+
```ts
13
+
import { db } from'src/lib/db.js'
14
+
import { logger } from'src/lib/logger.js'
15
+
```
16
+
17
+
In a TypeScript project the name of the source files for those imports are
18
+
db.ts and logger.ts
19
+
20
+
When authoring TypeScript, that's to be transpiled to JavaScript and then run by
21
+
Node, using the .js extension is typically what you should do, because that's
22
+
what the files to import will be named when Node executes them. But now we're
23
+
using vite-node, and vite-node runs the source files, not built files. And so
24
+
the extension should be empty, to let vite-node guess the file extension, or .ts
25
+
to explicitly tell it.
26
+
27
+
The solution is to update our custom resolver in packages/cli/src/lib/exec.js to
28
+
remove .js imports and let vite figure out the file extension:
0 commit comments