Skip to content

Commit

Permalink
esm: Update documentation with windows gotcha
Browse files Browse the repository at this point in the history
Explains that absolute specifiers and absolute paths
are not the same, and mentions what to do about it.

Refs: nodejs#31710
  • Loading branch information
Jon committed Mar 15, 2020
1 parent 2bec61e commit ea679b7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -803,14 +803,18 @@ property:

### Absolute file paths don't work on Windows
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:
`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.
To ensure cross platform compatibility, file paths should be converted into
URLs.
```
```js
import { pathToFileURL } from 'url';
const fileUrl = pathToFileURL(...your path here...).href;
const fileUrl = pathToFileURL('c:\\path\\to\\file.js').href;
await import(fileUrl)
await import(fileUrl);
```
### Mandatory file extensions
Expand Down

0 comments on commit ea679b7

Please sign in to comment.