Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type declarations in @types/loadable__component are broken when using typescript's moduleResolution:nodenext option #1017

Open
simon-paris opened this issue Jan 17, 2025 · 0 comments

Comments

@simon-paris
Copy link

🐛 Bug Report

When using typescript with {"module": "NodeNext","moduleResolution": "nodenext",}, the module @types/loadable__component exports {default:loadableFunc} when it should export loadableFunc.

To Reproduce

With this typescript config:

{
  "compilerOptions": {
    "baseUrl": ".",
    "module": "NodeNext",
    "moduleResolution": "nodenext",
    "jsx": "preserve",
    "allowSyntheticDefaultImports": false,
    "noEmit": true,
    "isolatedModules": true,
    "strict": true,
    "allowUmdGlobalAccess": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "verbatimModuleSyntax": true,
    "allowImportingTsExtensions": true
  },
  "include": [
    "./*.ts"
  ],
}

And this code:

import loadable from "@loadable/component";
loadable(() => import("./component.ts"));

Typescript will print this error:

test.ts:4:1 - error TS2349: This expression is not callable.
  Type 'typeof import("/Users/simonparis/temp/node_modules/@types/loadable__component/index")' has no call signatures.

4 loadable(() => import("./component.ts"));
  ~~~~~~~~

I don't fully understand this behavior, but setting type:module in the package.json file of the types package seems to fix it. Unsure if that would break anything. The types package may need both a CJS and ESM copy.

Expected behavior

This should not be an error.

Link to repl or repo (highly encouraged)

https://github.com/simon-paris/loadable-types-bug-repro

Issues without a reproduction link are likely to stall.

Run npx envinfo --system --binaries --npmPackages @loadable/component,@loadable/server,@loadable/webpack-plugin,@loadable/babel-plugin --markdown --clipboard

Paste the results here:

## System:
 - OS: macOS 13.5
 - CPU: (8) arm64 Apple M1 Pro
 - Memory: 113.53 MB / 16.00 GB
 - Shell: 5.9 - /bin/zsh
## Binaries:
 - Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
 - npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
 - pnpm: 9.11.0 - ~/.nvm/versions/node/v22.12.0/bin/pnpm
 - bun: 1.0.0 - ~/.bun/bin/bun
 - Watchman: 2024.11.18.00 - /opt/homebrew/bin/watchman
## npmPackages:
 - @loadable/component: ^5.16.4 => 5.16.4 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant