FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

[BUG] @stencil/core not building #3281

Open cmditch opened 3 years ago

cmditch commented 3 years ago

Bug Report Quick Checklist

Describe the bug

Snowpack does not seem to play nice with @stencil/core Seeing the error below when import stencil from '@stencil/core/internal/client' exists within code. This is a necessary import for Stencil custom elements.

Error: [16:19:08] [snowpack] Cannot find module ''../../../common/shadow-css-bb8fe40a.js'' from '/Users/cmditch/sandbox/snowpack-stencil/node_modules/@stencil/core/internal/client/index.js'

To Reproduce

git clone git@github.com:cmditch/snowpack-stencil-error.git
cd snowpack-stencil-error
yarn
yarn snowpack dev

Expected behavior

A build w/o errors.

Anything else?

When I load a stencil component via a <script> tag over the wire it works, but if I try to build it using snowpack it does not work. Stencil docs have an example of how to bundle a component w/ rollup here, so it seems like Stencil and rollup can play nice. Perhaps it's the way snowpack is configuring rollup.

Lastly, oddly enough the file/path ../../../common/shadow-css-bb8fe40a.js does not even exist within node_modules/@stencil/core. It's also not clear where this filename is being generated within their source.

rossng commented 3 years ago

Looks like it's being caused by this dynamic import in the Stencil code.

In the @stencil/core package, that has been compiled to something like:

    !BUILD.hydrateServerSide && BUILD.shadowDom && BUILD.shadowDomShim && 8 & o.$flags$ && (n = await import("./shadow-css.js").then((e => e.scopeCss(n, l, !1)))), 

I think this is the same root cause as #3094. Looks like esbuild doesn't natively support dynamic imports yet, so Snowpack would have to work around this but doesn't quite do it right atm. Though it's possible I've missed something and this is actually coming from Rollup - not 100% sure.

It appears that the Stencil team is also aware of this issue.