#Run build with external dependencies option outputs broken js

16 messages · Page 1 of 1 (latest)

stiff gulch
#

Hello!
I'm sorry ahead if this is not your area of responsibility, but vite's one. However, I noticed a strange behaviour with imports and found this MR that removes _hW export embedding. I assume that these things could be connected and lead to the following bug.

What I'm trying to do is to share dependencies via an external option in vite config. In my codebase there is an importmap script which specifies the urls to resolve qwik and other possible shared packages - https://github.com/sashkashishka/qwik-containers/blob/bug-external-dep/host/src/root.tsx#L25-L31.

When I build a prod bundle and run it via showcase command, this results in an error (see the screenshot). Thus, all the interactibity doesn't work at all.

But at the same time, when I'm not marking qwik as external dep, everything works fine. What I noticed in output files is the single qwik import definition without sharing, and two imports of qwik with sharing (see the video). Perhaps it is connected with this MR?

If this should be filed as a github issue, just let me know and I’ll carry it out and we will continue there

GitHub

it is not used directly, and the prefetch mechanisms take care of the import waterfall.

GitHub

Contribute to sashkashishka/qwik-containers development by creating an account on GitHub.

GitHub

Contribute to sashkashishka/qwik-containers development by creating an account on GitHub.

tepid yew
stiff gulch
#

No, the versions are the same - 1.14.1

tepid yew
stiff gulch
#

here is the actual error (screenshot 1)
screenshots 2 and 3 - the build output of clientside interactivity code. you can notice two imports of qwik and then code doesn't use _hW alias, but use actual _hW (which is not a defined variable)

tepid yew
stiff gulch
#

I’m not using module federation at all
This is an out of the box behaviour

#

The way I wanna share is to tell rollup to make some deps as external
Then use importmap script to point where to fetch such external deps

tepid yew
#

Well the bundling isn't working correctly, but that had nothing to do with qwik.

That _hW import error, can you show what's in the file?

stiff gulch
tepid yew
#

The one with the issue is q-C3p...
But it really is a build problem that has nothing to do with qwik

stiff gulch
#

what's been done:

  • add importmap script to the head
  • make @builder.io/qwik as an external dependecy in vite config
stiff gulch
#

yes, the problem was in the esbuild itself. they create a new alias for named import/export to avoid name shadowing in a module. and this is a feature, not a bug https://github.com/evanw/esbuild/issues/1027#issuecomment-803509189

the problem really occurs when qwik adds export { _hW } from '@builder.io/qwik'; to the files. it creates a situation when this _hW is actually used, but it is simply exported and not available in the module. Thus, esbuild doesn't know anything about the imported _hW variable and leaves usage of it as is (object in defineProperty remains unchanged and _hW doesn't receive a reference to the imported value).

On the next steps of transpilation, esbuild transforms the aforementioned statement into this:

import { _hW as _hW2 } from '@builder.io/qwik';

C = Object.freeze(
  Object.defineProperty(
    {
      __proto__: null,
      _hW, // this variable isn't declared anywhere
      s_XL7jPS8ihuM: M
    },
    Symbol.toStringTag,
    { value: 'Module' }
  ),
);

export { _hW2 as _hW}

Here is the plugin that looks up for export { _hW } from '@builder.io/qwik' statements alongside other imports of qwik and merges them. this way the esbuild transpiles everything correctly. Works for qwik v1.

https://github.com/sashkashishka/qwik-containers/blob/bug-external-dep/vite.qwik-export-import-merger.plugin.js

twin dove