microbundle
microbundle copied to clipboard
Noisy warning from Rollup: The 'this' keyword is equivalent to 'undefined'
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.
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.
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?
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?
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 😃
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.
is there any progress on this front? i just started using create-react-library and i need to get rid of this warning
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.
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!
Tbh we could just silence this warning globally.