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

Default imports don't work with module resolution node16 #58851

Closed
sharifzadesina opened this issue Jun 13, 2024 · 6 comments
Closed

Default imports don't work with module resolution node16 #58851

sharifzadesina opened this issue Jun 13, 2024 · 6 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@sharifzadesina
Copy link

sharifzadesina commented Jun 13, 2024

๐Ÿ”Ž Search Terms

"Default imports don't work with module resolution node16", "node16", "default imports"

๐Ÿ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about it

โฏ Playground Link

https://stackblitz.com/edit/stackblitz-starters-bakzhy

Node.js: Run using node src/index.js
Typescript: run using npx tsc and see the error!

๐Ÿ’ป Code

import pino from "pino";

const prettyTransport = {
  target: 'pino-pretty',
  level: 'debug',
  options: {
    translateTime: 'HH:MM:ss Z',
    ignore: 'pid,hostname',
  },
};

const p = pino({
  transport: {
    targets: [prettyTransport]
  },
  level: 'debug'
})

p.debug('test');

๐Ÿ™ Actual behavior

This expression is not callable.
  Type 'typeof import("/home/sina/Projects/test/node_modules/pino/pino")' has no call signatures.

๐Ÿ™‚ Expected behavior

It works in Node (tested with v18 and v20), why does typescript show the error?!

Just run the code above in NodeJS, we have no double default issue and everything works as expected.

Additional information about the issue

This is related to #53349 and #50058#issuecomment-1404411380.

@jakebailey
Copy link
Member

This package is incorrectly typed: https://arethetypeswrong.github.io/?p=pino%409.2.0

@sharifzadesina
Copy link
Author

sharifzadesina commented Jun 13, 2024

@jakebailey Can you elaborate a bit more?! Isn't node16 supposed to copy NodeJS behavior?! Also, we are not supposed to use node16 then?! because it is not NodeJS behavior.

@sharifzadesina
Copy link
Author

sharifzadesina commented Jun 13, 2024

We have the same issue for ioredis package.

But the interesting thing is, according to this, the ioredis package doesn't have invalid types.

Playground:

https://stackblitz.com/edit/stackblitz-starters-bakzhy

Node.js: Run using node src/ioredis.js
Typescript: run using npx tsc and see the error!

@sharifzadesina
Copy link
Author

sharifzadesina commented Jun 13, 2024

Just investigating further:

In ioredis, even when I comment module.exports =, the error won't be gone.

Screenshot 2024-06-13 112900

As you see, we now have only module.exports.default and export default.

Screenshot 2024-06-13 112731

@fatcerberus
Copy link

fatcerberus commented Jun 13, 2024

node16 does match Node runtime behavior for your code, the problem here is that the types for the package youโ€™re importing (its .d.ts files) are telling TS the wrong thing about how its exports are structured. In other words the problem is on the package authorโ€™s end.

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label Jun 13, 2024
@sharifzadesina
Copy link
Author

Found the cause of the problem. closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

4 participants