Skip to content

Commit

Permalink
Update esm.md
Browse files Browse the repository at this point in the history
Update es module documentation in accordance to nodejs#31710 by providing a gotcha for windows users
  • Loading branch information
jonerer committed Mar 12, 2020
1 parent ba68480 commit 2bec61e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,18 @@ property:

## Differences Between ES Modules and CommonJS

### 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 { pathToFileURL } from 'url';
const fileUrl = pathToFileURL(...your path here...).href;
await import(fileUrl)
```
### Mandatory file extensions
A file extension must be provided when using the `import` keyword. Directory
Expand Down

0 comments on commit 2bec61e

Please sign in to comment.