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
Hey, do you have any idea of why an import of an ESM lib can turn into a var init_somthg = __esm() import, with init_somthg() that is never called anywhere?
The problematic part is once bundled with esbuild --bundle --target=node14 --platform=node --loader:.ts=ts:
// ../documents/dist/fuzzy/index.js (It's an external lib but in an NPM workspace, hence the ../documents)varinit_fuzzy2=__esm({"../documents/dist/fuzzy/index.js"(){init_toc();}});
The documents lib in itself is build with tsc with target=ES2020 and module=ES2020, with type: module and sideEffects: false in package.json.
It's fuzzy2 because getToc uses a library that itself has fuzzy in its path. I've tried changing the directory name, it's reflected in the generated code (e.g. init_fuzzyy) but it still doesn't get called.
The thing is that init_fuzzy (the import of that library) is being called, but not init_fuzzy2, so I end up with a bunch of uninitialised things. getToc uses top-level variables that are defined in the file where it's defined, but that are not exported (which shouldn't make a difference because they get defined in the body of init_fuzzy2, but because it is not called, these variables are not initialised).
However, if I manually add init_fuzzy2(); somewhere in the bundled output, it works.
I'll post more info if you need, but I got to redact a lot of it. Cheers!
The text was updated successfully, but these errors were encountered:
Everything is exported explicitly in src/fuzzy/index.ts and src/PDF/index.ts (i.e. export { getToc } from './toc.ts') but I had a star export in src/index.ts (i.e. export * from './fuzzy').
By changing it to an explicit export (export { getToc } from './fuzzy'), the same code is generated, but init_fuzzy2 is called this time and everything works.
EHadoux
changed the title
__esm() initialisation never called__esm() initialisation never called with export * from statement.
Aug 2, 2021
Hey, do you have any idea of why an import of an ESM lib can turn into a
var init_somthg = __esm()
import, withinit_somthg()
that is never called anywhere?So, my smallest example for now:
PDF
is a class andgetToc
is a function.The problematic part is once bundled with
esbuild --bundle --target=node14 --platform=node --loader:.ts=ts
:The
documents
lib in itself is build withtsc
withtarget=ES2020
andmodule=ES2020
, withtype: module
andsideEffects: false
inpackage.json
.It's
fuzzy2
becausegetToc
uses a library that itself hasfuzzy
in its path. I've tried changing the directory name, it's reflected in the generated code (e.g.init_fuzzyy
) but it still doesn't get called.The thing is that
init_fuzzy
(the import of that library) is being called, but notinit_fuzzy2
, so I end up with a bunch of uninitialised things.getToc
uses top-level variables that are defined in the file where it's defined, but that are not exported (which shouldn't make a difference because they get defined in the body ofinit_fuzzy2
, but because it is not called, these variables are not initialised).However, if I manually add
init_fuzzy2();
somewhere in the bundled output, it works.I'll post more info if you need, but I got to redact a lot of it. Cheers!
The text was updated successfully, but these errors were encountered: