Skip to content

Bug: type issue in ts@4.8+ with esm #1348

Closed

Description

@Mister-Hope

A lot of plugins are exporting esm version

In a recent change in ts4.8, this leaves to type failue. as typescript@4.8+ will assume users are importing a commonjs module.

Here is a example:

TS will report issues with:

import commonjs from "@rollup/plugin-commonjs";

commonjs()

Saying the expression is not callable.

That's because a cjs module will have it's module.exports on default key, so:

import commonjs from "@rollup/plugin-commonjs";

commonjs.default()

is fine to typescript, but it's not acually working (because we do have esm modules using export default)

This happens under

  • esm package (with type: module in pacakge.json) and of course target: ESxxx in ts.config.json
  • together with moduleResolution: NodeNext is in ts.config.json

Activity

  1. Mister-Hope commented on Nov 19, 2022

    @Mister-Hope
    Author

    image

  2. Mister-Hope commented on Nov 19, 2022

    @Mister-Hope
    Author

    I belived this issue is releated to microsoft/TypeScript#50690

    Adding type: module in package.json can solve the problem at my use case, but I am not pretty sure if it will break other use cases.

  3. shellscape commented on Nov 19, 2022

    @shellscape
    Collaborator

    Thanks for opening an issue. Citing the issue template:

    🚨 Issues WITHOUT a valid reproduction WILL BE CLOSED!

    Please provide one by:

    1. Using the REPL.it plugin reproduction template at https://repl.it/@rollup/rollup-plugin-repro
    2. Provide a minimal repository link (Read https://git.io/fNzHA for instructions).
      Please use NPM for installing dependencies!
      These may take more time to triage than the other options.
    3. Using the Rollup REPL at https://rollupjs.org/repl/

    ⚠️ ZIP Files are unsafe and maintainers will NOT download them.

    We cannot make this any clearer. Please add a reproduction and we'll be happy to triage further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions