stencil icon indicating copy to clipboard operation
stencil copied to clipboard

bug: not all types are exported when using `dist-custom-elements`

Open theo-staizen opened this issue 1 month ago • 0 comments

Prerequisites

Stencil Version

v4.38.3 or later

Current Behavior

When using the dist-custom-elements without customElementsExportBehavior: 'single-export-module', the generated ./dist/components/index.d.ts does not export all the types exported by the ./src/index.ts

Current file contents (removed comments):

export declare const getAssetPath: (path: string) => string;
export declare const setAssetPath: (path: string) => void;
export declare const setNonce: (nonce: string) => void
export interface SetPlatformOptions {
  raf?: (c: FrameRequestCallback) => number;
  ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
  rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
}
export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;

Expected Behavior

If you set customElementsExportBehavior: 'single-export-module', then you get the expected result

export { MyComponent as MyComponent } from '../types/components/my-component/my-component';
export { defineCustomElement as defineCustomElementMyComponent } from './my-component';
export declare const getAssetPath: (path: string) => string;
export declare const setAssetPath: (path: string) => void;
export declare const setNonce: (nonce: string) => void

export interface SetPlatformOptions {
  raf?: (c: FrameRequestCallback) => number;
  ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
  rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
}
export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;
export * from '../types'; // THIS LINE IN PARTICULAR

System Info


Steps to Reproduce

  1. Run pnpm create stencil to init a new repo
  2. Check to make sure you have an dist-custom-elements output target with a customElementsExportBehavior with any value other than single-export-module
{
  type: 'dist-custom-elements',
  customElementsExportBehavior: 'auto-define-custom-elements', 
}
  1. Make sure that format is exported in index.ts
export { format } from './utils/utils';
  1. Run the build and look at ./dist/components/index.d.ts

Code Reproduction URL

https://github.com/theo-staizen/stencil-repro-custom-elements

Additional Information

  1. npm install
  2. npm run build
  3. check to see that export * from '../types'; is missing from the end of ./dist/components/index.d.ts
  4. uncomment customElementsExportBehavior: 'single-export-module' in stencil.config.ts
  5. Run the build again and check to see the that export * from '../types; is now included

theo-staizen avatar Dec 09 '25 22:12 theo-staizen