Skip to content

moduleResolution nodenext or node16 causes type errors with a default callable export (PostCSS)Β #50175

@brainkim

Description

@brainkim

Bug Report

πŸ”Ž Search Terms

nodenext, node16, ESM, exports, package.json, dependency, postcss

πŸ•— Version & Regression Information

[email protected]

⏯ Playground Link

Playground link with relevant code

Hilariously, the playground only seems to show this bug intermittently or doesn’t save the config. I can usually force the error to appear by setting the module configuration in the settings.

Screen Shot 2022-08-03 at 9 17 53 PM

πŸ’» Code

index.ts

import postcss from "postcss";

console.log(postcss());

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node16",
    "lib": ["esnext", "dom"],
    "strict": true
  }
}

package.json

{
  "name": "typescript-error-example",
  "private": true,
  "type": "module",
  "license": "UNLICENSED",
  "dependencies": {
    "postcss": "^8.4.14",
    "typescript": "^4.8.0-beta"
  }
}

typescript-example.zip

πŸ™ Actual behavior

Running npm i && tsc --noEmit on a directory configured like above produces the following error.

index.ts(3,13): error TS2349: This expression is not callable.
  Type 'typeof import("/Users/briankim/typescript-example/node_modules/postcss/lib/postcss")' has no call signatures.

πŸ™‚ Expected behavior

Running npm i && tsc --noEmit should produce no errors

Deleting "type": "module" from package.json or changing the moduleResolution to node in tsconfig.json makes the error go away. πŸ™ƒ

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions