Skip to content

Commit 729d5e2

Browse files
committed
ESM-compatible exports
Node.js handles ESM-CJS interoperability by using its [cjs-module-lexer](https://github.com/nodejs/cjs-module-lexer) to parse CJS files and turn their exports into named exports. cjs-module-lexer is deliberately limited in its capabilities. Switching export styles makes jsonfile's exports recognizable by cjs-module-lexer so that ESM code such aborts ``` import { readFileSync } from 'jsonfile' ``` can work as expected, without having to change jsonfile itself to ESM. Fixes #153
1 parent 17f97e1 commit 729d5e2

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ function writeFileSync (file, obj, options = {}) {
7878
return fs.writeFileSync(file, str, options)
7979
}
8080

81-
const jsonfile = {
81+
module.exports = {
8282
readFile,
8383
readFileSync,
8484
writeFile,
8585
writeFileSync
8686
}
87-
88-
module.exports = jsonfile

0 commit comments

Comments
 (0)