Skip to content

bug: unable to use jsxImportSource for Stencil JSX types with newer versions of TypeScript. #6180

Open
@trusktr

Description

@trusktr

Prerequisites

Stencil Version

4.26.0

Current Behavior

The @stencil/core package does not have a @stencil/core/jsx-runtime export path (or similar jsx-runtime path), making it not possible to use with TypeScript's jsxImportSource option.

Expected Behavior

Updated Stencil to work with newer TypeScript.

System Info

n/a

Steps to Reproduce

In any TypeScript project (doesn't matter if it is a React project, etc), try to put this at the top of a .tsx file to tell TypeScript to load JSX types for any JSX expressions from @stencil/core:

/* @jsxImportSource @stencil/core */

You'll get an error like

Cannot find module '@stencil/core/jsx-runtime' or its corresponding type declarations.

where /jsx-runtime is the conventional postfix that TypeScript appends to the path.

Code Reproduction URL

no URL yet

Additional Information

Without this feature, it is not possible to write Stencil components inside any other application that uses non-stencil JSX types.

The purpose of jsxImportSource is to allow for different files to use different JSX types. This makes it possible to, for example, compile certain files with one flavor of JSX (f.e. Solid.js JSX) and other files with Stencil JSX.

Solution

The fix is likely easy: just create an empty jsx-runtime.js file at the root of the package, along with a jsx-runtime.d.ts file at the root of the package that re-exports the JSX type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug: ValidatedThis PR or Issue is verified to be a bug within StencilHelp Wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions