microbundle icon indicating copy to clipboard operation
microbundle copied to clipboard

Noisy warning from Rollup: The 'this' keyword is equivalent to 'undefined'

Open smithki opened this issue 5 years ago • 9 comments

There is a noisy warning that occurs if the bundle imports a module which is compiled using TypeScript's tsc:

The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten

The warning is mostly harmless, so it would be nice to have the option of suppressing it.

smithki avatar Jul 12 '20 23:07 smithki

The warning is only harmless if its a check for this from something like tslib. In other cases, it's a nontrivial change in behavior (and almost always a bug).

One option I'd be okay with would be to silence the warning when it's generated by modules in node_modules, since it's not actionable there anyway.

developit avatar Jul 13 '20 00:07 developit

One option I'd be okay with would be to silence the warning when it's generated by modules in node_modules, since it's not actionable there anyway.

Good points, I like that approach!

EDIT:

Just wondering, would you also be open to a compromise that adds a new flag to the CLI? Something like --rollbarIgnoreWarnings THIS_IS_UNDEFINED,ANOTHER_WARNING_CODE,ETC...?

My use-case would be one where I've transpiled code using tsc before using microbundle... then again, I suppose this approach would work better if I just used rollup directly. What do you think?

smithki avatar Jul 13 '20 02:07 smithki

Heh - if you're running TS manually before passing things to Microbundle that would be a rollup use case.

Any particular reason you'd need to do that though?

developit avatar Jul 15 '20 12:07 developit

Heh - if you're running tax manually before passing things to Microbundle that would be a rollup use case.

Any particular reason you'd need to do that though?

I'd like to make use of TypeScript's project references feature for a monorepo. The issue I've found with using microbundle for that task is specifically development-related. It's been troublesome to find a way to microbundle watch a package and it's monorepo inter-dependencies in a way that doesn't cause undefined behavior. I've resorted to using tsc to compile CJS and ESM files while retaining microbundle for the UMD bundle. Not ideal, but it works for me because I don't need the UMD bundle to be hot-reloaded during development.

EDIT: It would be amazing if microbundle officially supported project references 😃

smithki avatar Jul 15 '20 16:07 smithki

More info on rollup/typescript warnings about rewriting THIS - https://github.com/rollup/rollup/issues/3788 - in particular a recommendation to use importHelpers in your Typescript, or alternatively, to use the rollup context option.

jaguart avatar Sep 23 '20 01:09 jaguart

is there any progress on this front? i just started using create-react-library and i need to get rid of this warning

divramod avatar Feb 27 '21 08:02 divramod

Hi, @developit,

Do you think that adding a new flag to the CLI to ignore the warning, as @smithki wrote, is a good idea?

I have the same annoying warning and I want to contribute with a PR for this issue.

lucassarcanjo avatar Aug 22 '22 01:08 lucassarcanjo

Do you think that adding a new flag to the CLI to ignore the warning, as @smithki wrote, is a good idea?

A new CLI flag would be very much unnecessary, IMO. We have a lot of flags as-is.

Silencing from node_modules, as Jason suggested, would be great though if you want to work on that!

rschristian avatar Aug 22 '22 01:08 rschristian

Tbh we could just silence this warning globally.

developit avatar Aug 22 '22 03:08 developit