-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bundling doesn't pull in all required dependencies #1619
Comments
I have put a minimal example in https://github.com/pedro-w/esbuild-example |
This is because the As a quick solution, you could use its ESM target in the // CORRECT, esbuild could know it depending on 'react'
var react = require('react')
// INCORRECT, esbuild can not know the dependencies
var r = require, react = r('react') |
Thanks for the swift response. I can confirm that this does fix the problem for me, though to be honest I don't fully understand it! Looking at the docs it seems that the default for node would be the equivalent of |
Right. This is mostly because people often incorrectly use the
MS do have to change the package, by making its This story would be too long to put here. If you'd like to learn "How to make a correct NPM package which runs on {Node.js {CJS | ESM} | Browser {script | script type=module}} context", You'd better look at some modern packages like Sindre Sorhus' pure ESM packages, vue@next, ... I'd like to share my pkg marshal, which works perfectly in Node.js CJS/ESM context and in bundlers (always choose the ESM one) and in browser (having an IIFE file). Again, this library is pure enough to do so. When the code has some side-effects (like a global state) that must be only run once, things will get more complex.
Did I say esbuild prefer For bigger projects that depend on many packages, you may want to adjust the file to be imported, which could be made by writing a plugin that helps esbuild finding the correct file in the |
Having esbuild handle this automatically is out of scope since esbuild only handles As mentioned above, workarounds are:
Closing as out of scope. |
I want to use esbuild on an npm project using jsonc-parser. esbuild seems to run OK but the bundle it creates does not contain all the required code.
I was able to produce a bundle using webpack.
Platform: Windows 10
Version: esbuild 0.12.28
Node: v14.17.5
The text was updated successfully, but these errors were encountered: