Skip to content

Commit

Permalink
Only URLs with a scheme in: file, data, and node are supported by the…
Browse files Browse the repository at this point in the history
… default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
  • Loading branch information
hlwen authored Aug 14, 2024
1 parent c37d2a6 commit a5f6a83
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugin/src/core/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Metafile, Plugin } from 'esbuild'
import { build } from 'esbuild'
import JSON5 from 'json5'
import type { Alias } from 'vite'
import url from "url";

Check failure on line 9 in plugin/src/core/compiler.ts

View workflow job for this annotation

GitHub Actions / lint

`url` import should occur before type import of `esbuild`

Check failure on line 9 in plugin/src/core/compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Prefer `node:url` over `url`

Check failure on line 9 in plugin/src/core/compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

Check failure on line 9 in plugin/src/core/compiler.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon

/* ===== esbuild begin ===== */

Expand Down Expand Up @@ -169,7 +170,7 @@ export async function loadFromCode<T = any>({
}: LoadFromCodeOptions): Promise<T | { [key: string]: T }> {
filepath = path.resolve(cwd, filepath)
const ext = isESM ? '.mjs' : '.cjs'
const file = `${filepath}.timestamp-${Date.now()}${ext}`
const file = url.pathToFileURL(`${filepath}.timestamp-${Date.now()}${ext}`)
await fsp.writeFile(file, code, 'utf8')
try {
const mod = await import(file)
Expand Down

0 comments on commit a5f6a83

Please sign in to comment.