TypeError: dts is not a function
agiveygives opened this issue · 8 comments
Checklist
- I can reproduce this issue when running this plugin on its own.
Other plugins, such asnode-resolve
are known to cause issues. - I am running this plugin on
.d.ts
files generated by TypeScript.
The plugin can consume.ts
and even.js
files (withallowJs: true
), but this is known to cause issues. - This issue is not related to rolling up
@types
.
The plugin ignores these by default, unlessrespectExternal
is set.@types
can contain hand-crafted code which is known to cause issues.
Notes
- I'm following https://plainenglish.io/blog/react-component-library-with-ts-and-rollup-77aca0c727bf#rollupconfigjs
- https://stackoverflow.com/a/74304876 fixes the issue, but I thought I would log the issue since the README suggests the approach in the blog post I was following.
Dependency versions
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"@types/react": "^18.0.27",
"classnames": "^2.3.2",
"react": "^18.2.0",
"rollup": "^3.14.0",
"rollup-plugin-dts": "^5.1.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"tslib": "^2.5.0",
"typescript": "^4.9.5"
}
Code Snipped
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
import external from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import dts from "rollup-plugin-dts";
const packageJson = require("./package.json");
export default [
{
input: "src/index.ts",
output: [
{
file: packageJson.main,
format: "cjs",
sourcemap: true,
name: 'kingdom-ui',
},
{
file: packageJson.module,
format: "esm",
sourcemap: true,
},
],
plugins: [
external(),
resolve(),
commonjs(),
typescript({ tsconfig: "./tsconfig.json" }),
postcss(),
terser(),
],
},
{
input: "dist/esm/types/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "esm" }],
external: [/\.css$/],
plugins: [dts()],
},
];
Error Message
[!] TypeError: dts is not a function
Some issue. dts is not a function
. Console logging shows that dts
is an object with a key called default
whose value is a function, but calling dts.default()
also doesn't work.
having the same issue, anyone found a solution?
dts
is an object with a key calleddefault
whose value is a function
Together with the warning that was in the stackoverflow post you linked:
Node tried to load your configuration file as CommonJS even though it is likely an ES module.
Its most likely some cjs interop problem?
This seems to work plugins: [dts.default()]
Same. But it finally works.However, I tried many ways and don't which step makes it work. Maybe you can rename your rollup.config.js
to rollup.config.mjs
?
It works using [dts.default()]
Slightly off-topic but the part const packageJson = require("./package.json");
is a huge red flag, even if it works, you're not supposed to use require
in the ESM program!
Correct way is according to Node.js Design Patterns 3rd. ED p.62:
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const packageJson = require("./package.json");
Be careful when copy-pasting snippets blindly from dubious sites!
It is working with dts.default()
,