Skip to content
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

"Ignoring this import because X was marked as having no side effects" on type imports #1785

Closed
fregante opened this issue Nov 19, 2021 · 2 comments

Comments

@fregante
Copy link

fregante commented Nov 19, 2021

https://github.com/g-plane/typed-query-selector is a type-only package, it's normal for it to be ignored (related: #1525), but it should not cause a warning.

Repro

npm i -D typed-query-selector
// main.ts
import 'typed-query-selector'
document.querySelector('div#app')
esbuild main.ts --bundle

Expected output

No error

document.querySelector('div#app')

Current output

 > file.ts:1:7: warning: Ignoring this import because "node_modules/typed-query-selector/shim.d.ts" was marked as having no side effects
     1 │ import 'typed-query-selector';
       ╵        ~~~~~~~~~~~~~~~~~~~~~~
   node_modules/typed-query-selector/package.json:13:2: note: "sideEffects" is false in the enclosing "package.json" file
    13 │   "sideEffects": false,
       ╵   ~~~~~~~~~~~~~
@hyrious
Copy link

hyrious commented Nov 20, 2021

I believe this warning is for preventing people from incorrectly marking a package as no side-effect when it actually has. Normally the import "xxx" statement is used for side effects, like importing from core-js. Esbuild can not ignore this statement like other import types because when you write import "xxx", you expect something happen globally (but this thing happens in types world, so esbuild don't know).

One possible solution is putting this package in the types field in tsconfig.json.

@evanw evanw closed this as completed in 93ed5dd Nov 20, 2021
@fregante
Copy link
Author

Thanks @evanw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants