Skip to content

Commit

Permalink
Improve ESM code example in documentation (#4583)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
berniegp and lukastaegert committed Jul 27, 2022
1 parent 22b2f68 commit c526974
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/01-command-line-reference.md
Expand Up @@ -302,7 +302,9 @@ There are some potential gotchas when using `.mjs` on Node 13+:
// rollup.config.mjs
import { readFileSync } from 'fs';

const packageJson = JSON.parse(readFileSync('./package.json'));
// Use import.meta.url to make the path relative to the current source file instead of process.cwd()
// For more info: https://nodejs.org/docs/latest-v16.x/api/esm.html#importmetaurl
const packageJson = JSON.parse(readFileSync(new URL('./package.json', import.meta.url)));
...
```
Expand Down

0 comments on commit c526974

Please sign in to comment.