You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In development mode, some chunks in node_modules/.vite/deps/ are built by putting modules that import one another into the same chunk.
This leads to the import statement of the importing module being removed, because the definition of the imported item now is in the same (chunk) .js file.
Problem: When an import of an exported variable is replaced, the imported module is placed AFTER the importing module in the chunk .js file. But var hoisting still has a sequence to it, assigments are not done in (mathematical) parallel. This leads to undefined when the module importing a constant from another one uses it to calculate another (module top level) constant.
// ModuleBvarMoL=ALMOST_MoL+1;// NaN because Almost_MoL is undefinedfunctionlogConst(){console.log(MoL);// NaN}// ModuleAvarALMOST_MoL=41;
Reproduction requires exported const in one module imported by another module to (on the top level, immediately) produce another const using the imported one.
Then the chunk producing algorithm has to create a chunk that replaces the import by adding the imported module after the importing module in the same .js chunk.
I'll see if I can get an archive that reproduces this, if that is necessary. I'm not sure the chunk producing algorithm always produces such chunks? So I'm not sure how easy it is.
The minimum example to see that one cannot replace ìmport(of constants used immediately) withvar` and rely on hoisting simply is
varT=S+1;varS=41;console.log(T);// NaN
Not sure about a bug report. Is this a bug?
I would have to provide a workable example, but I'm not sure the chunk producing algorithm will always create a chunk exactly like this. It could just keep the modules in different chunks, and the imports remain and it all works.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In development mode, some chunks in
node_modules/.vite/deps/
are built by putting modules that import one another into the same chunk.This leads to the
import
statement of the importing module being removed, because the definition of the imported item now is in the same (chunk) .js file.Problem: When an import of an exported variable is replaced, the imported module is placed AFTER the importing module in the chunk .js file. But
var
hoisting still has a sequence to it, assigments are not done in (mathematical) parallel. This leads toundefined
when the module importing a constant from another one uses it to calculate another (module top level) constant.Example:
Source
ModuleA:
ModuleB:
Chunk
Reproduction requires exported
const
in one module imported by another module to (on the top level, immediately) produce anotherconst
using the imported one.Then the chunk producing algorithm has to create a chunk that replaces the import by adding the imported module after the importing module in the same .js chunk.
I'll see if I can get an archive that reproduces this, if that is necessary. I'm not sure the chunk producing algorithm always produces such chunks? So I'm not sure how easy it is.
The minimum example to see that one cannot replace ìmport
(of constants used immediately) with
var` and rely on hoisting simply isNot sure about a bug report. Is this a bug?
I would have to provide a workable example, but I'm not sure the chunk producing algorithm will always create a chunk exactly like this. It could just keep the modules in different chunks, and the imports remain and it all works.
Beta Was this translation helpful? Give feedback.
All reactions