Open jdharrisnz opened 5 months ago
Same issue encountered.
Alternatively
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
commonjs(),
Which again isn't nice, but allows you to keep using a TS config file.
Might be off-topic, but here is another workaround to keep the typings:
// rollup.config.ts
import _eslint from '@rollup/plugin-eslint';
import _typescript from '@rollup/plugin-typescript';
// NOTE: remove once import errors are fixed for their respective packages
const eslint = _eslint as unknown as typeof _eslint.default;
const typescript = _typescript as unknown as typeof _typescript.default;
// ...
export default {
// ...
plugins: [eslint(), typescript()]
};
This issue sounds like https://github.com/microsoft/TypeScript/issues/58890
The cause appears to be related to how TypeScript classifies imports. https://github.com/microsoft/TypeScript/issues/58890#issuecomment-2177318634 concluded that if the .d.ts
file is in a CJS scope, the import will be treated CJS.
In the case of @rollup/plugin-commonjs
the types live at types/index.d.ts
which is outside the ESM scope (dist/es/
).
This issue is fixable, but it will mean duplicating .d.ts
in the published package.
Expected Behavior
Compile as usual. Use
npm run bug
in my repl to see what happens.Actual Behavior
Produces errors when compiling:
Additional Information
Key ingredients are:
"type": "module"
in package.json"moduleResolution": "NodeNext"
or"Node16"
in tsconfig.jsonThe workaround is to use a JavaScript config file, so this is really the smallest of inconveniences, but it's something to fix nonetheless.