-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Preserve es modules in babel config #4013
Conversation
Should we add |
@luin Adding "type": "module" seems to break webpack (build/dev-server). We should be fine without it since we don't need it to be run in node. I added "sideEffects":false to potentially help with treeshaking |
I assume quill.js has side effects as it registers formats? |
They won't be discarded by bundlers (webpack/vite) as far as I know. Their tree shaking is very conservative and requires explicit Edit: found the relavent documentation from webpack |
Thanks! I removed |
@luin @fnlctrl Shipping without
|
To get this to work on Webpack with {
test: /\.m?js/,
resolve: {
fullySpecified: false
}
} |
Also I'm not personally convinced with shipping this as ESM-only. Feels massively breaking. |
Super simple repro repo for the issue. Just run https://stackblitz.com/edit/stackblitz-starters-1s5ssr?file=index.spec.js |
@alecgibson Good point on the jsdom issue! I thought users won't run Quill in Node.js. Do you have any suggestions for #4007? |
@luin there's a good write-up and quick-fix solution here: https://www.npmjs.com/package/default-import The basic issue is that Quill mixes default and named exports, which doesn't make ESM happy. The short-term solution is that ESM consumers can use the import _Quill from 'quill';
import { defaultImport } from 'default-import';
const Quill = defaultImport(_Quill);
const quill = new Quill('#editor', {
theme: 'snow',
}); Here's a fixed fork of the Stackblitz in #4007 : https://stackblitz.com/edit/esbuild-template-hwaow1?file=package.json The long-term solution is to stop mixing named and default exports in Quill. |
(We'd also need to revert this change, which breaks Node.js usage) |
@alecgibson Will take a look! Probably we can revert the change and also export Quill as a named export (while keep the default export for backward compatibility) and advocate the named export usage. WDYT? import { Quill } from 'quill';
import { Quill } from 'quill/core'; The only downside I can see is |
@luin I've not tested it, but I imagine that's a sensible solution; we'd ideally do this everywhere, because we mix default/named exports in quite a few places. |
Yeah actually I'm thinking about expose all things from the main file, so instead of import Block from 'quill/blots/block'; Users could do import { Block } from 'quill';
import { Block } from 'quill/core'; We will still keep |
@alecgibson Just wanted to double-check, v1.3.7 and v2.0.0-dev.4 are both use ESM format and looks like we only changed it to CJS in 2.0.0 beta version. Is that something that you had fixed in your fork version before 2.0.0 beta? |
@luin I'm not sure I understand what you mean? |
@alecgibson https://www.npmjs.com/package/quill?activeTab=code 1.3.7 and 2.0.0-dev.4 also use ESM import, did you find the same issue with those versions? |
@luin we haven't run into this ourselves, but:
Maybe I was wrong about dropping CJS being breaking? I forget; we've been on the |
@alecgibson Yeah I tried a couple of approaches and none of them works well (turns out default exporting is hard). So I think we have to keep the current approach (we export ESM for years in 2.0.0-dev.4 so don't consider it as a breaking change). For Node.js usage, users would have to transpile the files. Fortunately it's straightforward with Jest: // jest.config.js
module.exports = {
transform: {
"\\.[jt]sx?$": "babel-jest",
},
transformIgnorePatterns: ["node_modules/(?!quill|parchment|lodash-es)"],
}; |
@luin you mean you're not changing anything? Feels a bit broken exporting ESM code without |
@alecgibson found a maybe relavent stackoverflow post about using mocha with esmodules https://stackoverflow.com/a/60522428
|
Adding
I don't understand why we can't just set |
This reverts commit 5fa786c. Upstream merged a change that ships ESM directly, with no transformation through babel, and without marking the library as `"type": "module"` This breaks some of our Node.js tests, which (correctly) complain that Quill shouldn't be using `import` statements without declaring itself as an ESM library with `"type": "module"`. This change just reverts the break.
I'm trying make Quill a pure ESM package and so far it works good: #4047 and it passed https://arethetypeswrong.github.io/ I can't find a way to support both CJS and ESM at the same time due to bundlers behave differently on handling default exports, especially as we are also exposing TypeScript declarations. |
Okay I think so long as Quill goes properly ESM, that would be good. This weird inbetween state of using ESM but not declaring ESM is poorly defined in my opinion. |
Revert "Preserve es modules in babel config (slab#4013)"
For users installing from npm, they already have a bundler that can handle es modules.
For users that want to run quill in nodejs directly, it's currently not possible due to side effects calling DOM
By preserving modules, it allows third party dependencies (e.g. lodash-es) to be tree shaken. Currently lodash-es is fully bundled by users because of es modules transpiled to
require()
https://www.npmjs.com/package/quill/v/2.0.0-rc.1?activeTab=code