Stencil v2.10 removed `attachShadow` from bundle

Hi everyone,

Our library run stencil v2.8.1. One of our consumer installed a dependency that in turn installed a higher version of stencil, 2.10. Now their build process is breaking because export 'attachShadow' (imported as 'attachShadow') was not found in '@stencil/core/internal/client'. Digging into the compiled code, attachShadow is indeed not exported anymore from @stencil/core/internal/client, when it is on lower versions (until 2.7 I think). Is this intended? Wouldn’t be considered a breaking change?

Thanks for your help.

Hey there :wave:

Can you do me a favor and do one of two things for us?

  1. If the code is directly importing from that path (@stencil/core/internal/client), could you point us to that code? It’s not immediately clear if the consumer is a consumer package that you/your company owns or something that another company/party owns
  2. If the above is not possible, can you/the person running into this issue post back the results of running npm ls @stencil/core?

Thanks!

Hi Ryan,
Thanks for answering.

For more context, we have an in-company design system based on stencil, and the consumer is one of our owned application (but different team).
The design system has stencil as dependency:

{
  "name": "@cosmos/web",
  "dependencies": {
    "@stencil/core": "^2.8.1"
  }
}

And the app depends on our design system:

{
  "dependencies": {
    "@comsos/web": "^2.21.0"
  }
}

We were also able to reproduce the issue by installing the last version of stencil on a testing application depending on our design system:

{
  "dependencies": {
    "@comsos/web": "^2.21.0",
    "@stencil/core": "2.10.0"
  }
}

The code is not directly importing @stencil/core/internal/client. It retrieve components from the bundle (compiled through the dist-custom-elements-bundle output target) like this:

import { CosmosButton } from '@cosmos/web';

The compiled bundle import the path:

// @cosmos/web/dist/custom-elements/index.js
// Generated by stencil
import { attachShadow, h, createEvent, Host, proxyCustomElement } from '@stencil/core/internal/client';

And if we look at the client file, here is the export:

// @stencil/core/internal/client v2.10
// No mention of attachShadow
...
export { Build, CSS, Context, Fragment, H, H as HTMLElement, Host, STENCIL_DEV_MODE, addHostEventListeners, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, doc, forceModeUpdate, forceUpdate, getAssetPath, getConnect, getContext, getElement, getHostRef, getMode, getRenderingRef, getValue, h, insertVdomAnnotations, isMemberInElement, loadModule, modeResolutionChain, nextTick, parsePropertyValue, plt, postUpdateComponent, promiseResolve, proxyComponent, proxyCustomElement, readTask, registerHost, registerInstance, renderVdom, setAssetPath, setErrorHandler, setMode, setPlatformHelpers, setPlatformOptions, setValue, styles, supportsConstructibleStylesheets, supportsListenerOptions, supportsShadow, win, writeTask };

But for the previous version

// @stencil/core/internal/client v2.10
// attachShadow is present
...
export { Build, CSS, Context, Fragment, H, H as HTMLElement, Host, STENCIL_DEV_MODE, addHostEventListeners, attachShadow, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, doc, forceModeUpdate, forceUpdate, getAssetPath, getConnect, getContext, getElement, getHostRef, getMode, getRenderingRef, getValue, h, insertVdomAnnotations, isMemberInElement, loadModule, modeResolutionChain, nextTick, parsePropertyValue, plt, postUpdateComponent, promiseResolve, proxyComponent, proxyCustomElement, readTask, registerHost, registerInstance, renderVdom, setAssetPath, setErrorHandler, setMode, setPlatformHelpers, setPlatformOptions, setValue, styles, supportsConstructibleStylesheets, supportsListenerOptions, supportsShadow, win, writeTask };

Running npm ls @stencil/core on a bugged app output this:

├─┬ @cosmos/web@2.15.0
│ └── @stencil/core@2.10.0 deduped
└── @stencil/core@2.10.0

Having a look into the docs, the update command pin the stencil version. I guess this would fix the issue, also it does not align with our own best practices regarding dependency management.

I hope this can help! If I can provide any more information, please let me know.

Cheers!

Thanks for all the information! It’s super helpful. Like you mentioned, the fix for this situation would be to update @cosmos/web's dependency of @stencil/core to 2.10.0 and recompile your web components. Sorry for any headache this may have caused!

No worries! We had already an idea of the fix before posting, but we wanted to make sure there was no issue on stencil’s side. We felt like a breaking change had been introduced in a minor version.
To prevent that, we now pinned our dependency on stencil so that no higher minor version is installed when using our design system. It seems to be a good practice from stencil but maybe it would be worth it to make it explicit in the documentation.
In any case thanks again for your help!