-
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
Import gets tree-shaken despite looking like it's being protected by sideEffects #2465
Comments
It does not happen on bare esbuild: > echo 'import "@interactjs/auto-start"' | esbuild --bundle
[WARNING] Ignoring this import because "node_modules/@interactjs/auto-start/index.js" was marked as having no side effects [ignored-bare-import]
<stdin>:1:7:
1 │ import "@interactjs/auto-start";
╵ ~~~~~~~~~~~~~~~~~~~~~~~~
It was excluded from the "sideEffects" array in the enclosing "package.json" file
node_modules/@interactjs/auto-start/package.json:21:2:
21 │ "sideEffects": [
╵ ~~~~~~~~~~~~~
1 warning
(() => {
})(); I think this should be a Vite-specific issue, as they have a special Update: It seems both a bug in Vite and rollup (see comments in the vite issue). |
I'm a bit confused, doesn't your command line invocation actually demonstrate the problem? Because If instead I invoke > echo 'import "@interactjs/auto-start"' | esbuild --bundle --ignore-annotations
(() => {
// node_modules/@interactjs/utils/domObjects.js
var domObjects = {
init,
document: null,
};
// ...
// ...
// ...
// node_modules/@interactjs/auto-start/plugin.js
var plugin_default = {
id: "auto-start",
install(scope2) {
scope2.usePlugin(base_default);
scope2.usePlugin(hold_default);
scope2.usePlugin(dragAxis_default);
}
};
// node_modules/@interactjs/auto-start/index.js
interact_default.use(plugin_default);
})(); |
Oops, yes. So it is both a bug in 3 tools :-/ |
I'm not sure it's related to that other bug. If I bundle with |
Can someone describe how to reproduce the problem? And describe what isn't expected about the output? Here's what I did:
I get a lot of output that looks like this (and there are no warnings): (() => {
// node_modules/@interactjs/utils/domObjects.js
var domObjects = {
init,
document: null,
DocumentFragment: null,
SVGElement: null,
SVGSVGElement: null,
SVGElementInstance: null,
Element: null,
HTMLElement: null,
Event: null,
Touch: null,
PointerEvent: null
};
function blank() {
}
var domObjects_default = domObjects;
function init(window3) {
const win2 = window3;
domObjects.document = win2.document;
domObjects.DocumentFragment = win2.DocumentFragment || blank;
domObjects.SVGElement = win2.SVGElement || blank;
domObjects.SVGSVGElement = win2.SVGSVGElement || blank;
domObjects.SVGElementInstance = win2.SVGElementInstance || blank;
domObjects.Element = win2.Element || blank;
domObjects.HTMLElement = win2.HTMLElement || domObjects.Element;
domObjects.Event = win2.Event;
domObjects.Touch = win2.Touch || blank;
domObjects.PointerEvent = win2.PointerEvent || win2.MSPointerEvent;
}
// node_modules/@interactjs/utils/isWindow.js
var isWindow_default = (thing) => !!(thing && thing.Window) && thing instanceof thing.Window;
...
// node_modules/@interactjs/auto-start/plugin.js
var plugin_default = {
id: "auto-start",
install(scope2) {
scope2.usePlugin(base_default);
scope2.usePlugin(hold_default);
scope2.usePlugin(dragAxis_default);
}
};
// node_modules/@interactjs/auto-start/index.js
interact_default.use(plugin_default);
})(); I would need both the exact input files and the esbuild command arguments used to be able to reproduce and fix this. |
I think it's a Windows only bug. I just tried your steps, and they fail on my Windows 10 x64, but work on my Ubuntu 22 where I get output matching yours. Maybe the "sideEffects": [
"**/index.js",
"**/index.prod.js",
]
Versions:
|
I can confirm that it's a Windows-specific issue. The pattern uses |
This import gets wrongly tree shaken, together with it's side effects, by
esbuild 0.14.54
, used throughvite 3.0.7
:interact.js
docs showing above import is the way they recommend usage (see sidebar):https://interactjs.io/docs/installation/#npm-streamlined
Installed
node_modules/@interactjs/auto-start/index.js
looks like this:Installed
node_modules/@interactjs/auto-start/package.json
looks like this (simplified):vite
config, from https://vitejs.dev/guide/migration.html#experimentalAs a workaround I did this, but it's not documented anywhere on their site, so it might break in the future:
The text was updated successfully, but these errors were encountered: