-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[FeatureRequest] Allow users to specify which modules are commonjs #447
Comments
For context: this current behavior is inspired by TypeScript, which does the same thing. I'm wary of introducing lots of configuration options because it can easily get to be overwhelming. In general I'm interested in exploring avenues for figuring stuff out automatically if possible before adding configuration options. One could argue that there could be automatic solutions as well. For example, if a module doesn't contain Another solution, which aligns with large parts of the JavaScript ecosystem such as browsers and node, is to have a system of rules to specify which modules are which type (called the "goal" of the parser in the specification). For example, in node ES6 modules must be marked in However, I don't think any work should be done on this before understanding the real-world implications. The bundler is already complex enough and I don't want to just accumulate complexity for complexity's sake. Did this come up because you have a problem with a specific library that's not working? Or is this just a theoretical concern? |
Agree with this. It seems like what babel does.
Our library has some type-only |
The behavior I described has now been implemented. From the release notes:
Does this behavior solve your issue? If so, I'd like to close this even though there is no way to specify which modules are CommonJS given that the underlying issue has been resolved. |
I'm going to close this since the underlying |
I'm working with a library which can either be consumed in a CJS or IIFE format. I'm importing it as an IIFE using ESM's static import syntax but esbuild treats it like a CJS module because of the prescence of CJS |
Currently, as code suggested, files without ES6 syntax are treated as CommonJS modules :
https://github.com/shrinktofit/esbuild/blob/1d9348337a01efe2eb79eb4f2ea78f1af313b38d/internal/bundler/linker.go#L1025-L1027
This may not be a good idea.
Empty files can be easily produced by TypeScript if source files contain type-only declarations. Another cases includes "import execution":
esbuild will generate
_commonjs
wrapper for CommonJS modules, even unexpectly, modules that transitively exporting star from CommonJS modules are also considered as CommonJS modules. By an entry point doing so, that entry point will only export a default binding, even if in actual it exports many named bindings.I would suggest the following rules:
Related: #442
The text was updated successfully, but these errors were encountered: