plugins icon indicating copy to clipboard operation
plugins copied to clipboard

`types` are wrong configed

Open JounQin opened this issue 8 months ago • 10 comments

  • Rollup Plugin Name: All plugins
  • Rollup Plugin Version: 16.0.1
  • Rollup Version: 4.39.0
  • Operating System (or Browser): macOS
  • Node Version: v22.14.0
  • Link to reproduction (⚠️ read below):

https://arethetypeswrong.github.io/?p=%40rollup%2Fplugin-node-resolve%4016.0.1

Image

Expected Behavior

ESM should be has its own definition.

Actual Behavior

Import resolved to a CommonJS type declaration file, but an ESM JavaScript file.

Additional Information

JounQin avatar Apr 06 '25 10:04 JounQin

We have a big project ahead with going ESM for all plugins - Node 18 is now out of LTS and 20 and 22 support clean ESM require in commonjs.

shellscape avatar Apr 06 '25 12:04 shellscape

@shellscape It's about types, not runtime codes.

JounQin avatar Apr 06 '25 12:04 JounQin

think about it carefully:)

shellscape avatar Apr 06 '25 12:04 shellscape

think about it carefully:)

No idea what's your meaning, when using type: module + tsconfig with module: node16:

Image

commonjs.default is required by TypeScript, but it's wrong. commonjs.default is undefined.

error TS2349: This expression is not callable.
  Type 'typeof import("/Users/JounQin/Workspaces/GitHub/pkgr/node_modules/@rollup/plugin-commonjs/types/index")' has no call signatures.

107 const cjs = (sourceMap: boolean) => commonjs({ sourceMap })

I have to use the following for workaround

https://github.com/un-ts/pkgr/blob/a4acfbcab1a22236605f56c7b4355a63bc656877/packages/rollup/src/config.ts#L108

import { __importStar } from 'tslib'

const cjs = (sourceMap: boolean) =>
  __importStar(commonjs).default({ sourceMap })

JounQin avatar Apr 06 '25 12:04 JounQin

When we ship only esm the types will be only esm and this will self-resolve. Last I'll be commenting on this issue until the esm migration starts.

shellscape avatar Apr 06 '25 12:04 shellscape

@shellscape Nope, .d.ts and .d.mts should be splitted for require and import, it's a common mistake for TypeScript packages, I can raise a PR for them.

JounQin avatar Apr 06 '25 12:04 JounQin

We're going to use tshy. Please chill.

shellscape avatar Apr 06 '25 12:04 shellscape

We're going to use tshy. Please chill.

@shellscape Then why you're saying:

When we ship only esm the types will be only esm and this will self-resolve.

It doesn't required to be ESM only.

JounQin avatar Apr 06 '25 12:04 JounQin

Are there any news on this thread? The issue still exists today and it does not allow to use Typescript for Rollup configs

just-boris avatar Oct 31 '25 19:10 just-boris

@just-boris please show restraint in adding noise. your reply doesn't contribute anything useful. Follow the repo's activity if you wan to know what's going on in the repo. Further noise will result in the issue being locked.

shellscape avatar Oct 31 '25 20:10 shellscape