Syntactically incorrect JS output with `declare const` globals -- due to Rollup treeshaking / side-effects
See original GitHub issueWhat happens and why it is wrong
I ran into a werid result, as you can see the
const T = COMMENT_OPTIONS,
V = PAGE_INFO_I18N;
VALINE_I18N;
is absolutly wrong, and will return an error Uncaught SyntaxError: Unexpected token ':'
after VALINE_I18N
replace by an object.
The project is working good for the past week, when it suddenly ran into this issue.
At a glance, I regard this as a temp
error, but this issue still happens after I:
-
delete
node_modules/.temp
-
delete the whole
node_modules/
I am not sure if it is a bug (it probably not), but is there other temp or cache I missed?
Sorry for not providing the config, but I think for this question it’s not needed. And won’t help.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Tree shaking too aggressive? · Issue #786 · rollup ... - GitHub
Rollup should recognize that document is not a global variable, and accessing any variables not controlled by Rollup can have a side effect....
Read more >Tree Shaking - webpack
A "side effect" is defined as code that performs a special behavior when imported, other than exposing one or more exports. An example...
Read more >How to deal with side effects in tree shaking code?
In one of my modules, I access the global Audio constructor and use it to determine which audio files the browser can play...
Read more >Reduce JavaScript payloads with tree shaking - web.dev
Tree shaking is a form of dead code elimination. The term was popularized by Rollup, but the concept of dead code elimination has...
Read more >Tree-Shaking in JavaScript with Rollup - CodinGame
This results in the elimination of code in our files and dependencies that is effectively unreachable. In a metaphorical sense, it's like shaking...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Edited, I looked into my repo commit, I did not import a.
It seems that rollup mark
CONST_A
with side effect because it does not know what’s it’s value and preserve it, but the declared a is removed because it’s unused, so that rollup proudly gives:Any way, it should not be a problem with this repo. I was new with rollup at that time.
It’s been a long time. I can tell that the original one is that:
I am not sure about the real content in
module.ts
, but at that time it’s not a cache error, intead, it produce the weird result with:After investigating for sometime, I realize that rollup seems doing the correct thing, but it actually can produce an error if the content is replaced by an object, so rollup should better produce:
So I decide to close this in this repo. Also I mananged to find a workaround (instead of fixing it at that time).
I am not sure if the issue is still reproductable now, and I think that I was too lazy to raise another issue to rollup at that time, because it’s hard to say rollup was wrong.