-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
npm init
npm install handlebars@4.7.7
echo 'import Handlebars from "handlebars";' > index.mjs
npx esbuild index.mjs --bundle
gives an error that makes it seems like esbuild is trying to use lib/index.js from main instead of dist/cjs/handlebars.js from browser:
✘ [ERROR] Could not resolve "fs"
node_modules/handlebars/lib/index.js:17:19:
17 │ var fs = require('fs');
╵ ~~~~
The package "fs" wasn't found on the file system but is built into node. Are
you trying to bundle for node? You can use "--platform=node" to do that, which
will remove this error.
1 error
I think this may be due to handlebars having browser as an object instead of a string, perhaps this causes esbuild to use the main instead of browser?
"main": "lib/index.js",
"types": "types/index.d.ts",
"browser": {
".": "./dist/cjs/handlebars.js",
"./runtime": "./dist/cjs/handlebars.runtime.js"
},
Changing the import to go direct to the file like:
import Handlebars from "handlebars/dist/cjs/handlebars.js";
seems to work, but seems like this shouldn't need to be done.
Metadata
Metadata
Assignees
Labels
No labels