Skip to content

Commit ea679b7

Browse files
author
Jon
committed
esm: Update documentation with windows gotcha
Explains that absolute specifiers and absolute paths are not the same, and mentions what to do about it. Refs: #31710
1 parent 2bec61e commit ea679b7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

doc/api/esm.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,18 @@ property:
803803

804804
### Absolute file paths don't work on Windows
805805
806-
Note that `import` accepts _absolute specifiers_. These are similar to _absolute paths_ on linux and MacOS, and therefore they are also accepted. But on Windows, importing an _absolute path_ to a file will not work. Therefore, to ensure cross platform compatibility, be sure to turn your file paths into urls, like so:
806+
`import` accepts _absolute specifiers_. These are similar to _absolute paths_
807+
on linux and MacOS, and therefore they are also accepted.
808+
But on Windows, importing an _absolute path_ to a file will not work.
809+
To ensure cross platform compatibility, file paths should be converted into
810+
URLs.
807811
808-
```
812+
```js
809813
import { pathToFileURL } from 'url';
810814
811-
const fileUrl = pathToFileURL(...your path here...).href;
815+
const fileUrl = pathToFileURL('c:\\path\\to\\file.js').href;
812816
813-
await import(fileUrl)
817+
await import(fileUrl);
814818
```
815819
816820
### Mandatory file extensions

0 commit comments

Comments
 (0)