Skip to content

[TS 4.1] react-jsx breaks a type:module package #41623

Closed
@daniele-orlando

Description

@daniele-orlando

TypeScript Version: 4.1.2 AND next

Search Terms: jsx react-jsx jsxImportSource react/jsx-runtime extension

When using the new jsx: react-jsx flag, the emitted files should point to react/jsx-runtime.js instead of react/jsx-runtime. Otherwise Webpack fails.

Code

// my-lib/package.json
{
    "type": "module",
}
// my-lib/tsconfig.json
{
    "compilerOptions": {
        "jsx": "react-jsx",
    },
}
// my-lib/my-component.tsx

function MyComponent() {
    return (
        <div>Hello World<div/>
    )
}

Expected behavior:

The output of the build should be

// my-lib/my-component.js
import { jsx as _jsx } from "react/jsx-runtime.js"

// ...

The react/jsx-runtime should have the .js extension.

Actual behavior:

The output of the build is

// my-lib/my-component.js
import { jsx as _jsx } from "react/jsx-runtime"

// ...

The react/jsx-runtime has no extension. Which breaks Webpack 5 (5.6).

Module not found: Error: Can't resolve 'react/jsx-runtime' in 'project'
Did you mean 'jsx-runtime.js'?
BREAKING CHANGE: The request 'react/jsx-runtime' failed to resolve only because it was resolved as fully specified (probably because the origin is a '.mjs' file or a '.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

For reference:
facebook/react#20235
babel/babel#12210

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions