Skip to content

Commit

Permalink
fix: bundle as an ES Module
Browse files Browse the repository at this point in the history
When I just added `--format=esm`, I saw runtime errors about `require`
not being defined.

I used a trick from
evanw/esbuild#946 (comment)
that seems to compile and execute happily.
  • Loading branch information
EricCrosson committed Nov 12, 2023
1 parent d127ed1 commit 7561499
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test/"
],
"scripts": {
"build": "esbuild src/main.js --bundle --platform=node --outfile=dist/index.js",
"build": "esbuild src/main.js --bundle --platform=node --format=esm --outfile=dist/index.js --banner:js='import { createRequire as topLevelCreateRequire } from \"module\"; const require = topLevelCreateRequire(import.meta.url);'",
"test": "node --test test/test-*"
},
"dependencies": {
Expand Down

0 comments on commit 7561499

Please sign in to comment.