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

TypeError: dts is not a function #247

Closed
3 tasks done
agiveygives opened this issue Feb 8, 2023 · 8 comments · Fixed by #274
Closed
3 tasks done

TypeError: dts is not a function #247

agiveygives opened this issue Feb 8, 2023 · 8 comments · Fixed by #274

Comments

@agiveygives
Copy link

agiveygives commented Feb 8, 2023

Checklist

  • I can reproduce this issue when running this plugin on its own.
    Other plugins, such as node-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 (with allowJs: true), but this is known to cause issues.
  • This issue is not related to rolling up @types.
    The plugin ignores these by default, unless respectExternal is set. @types can contain hand-crafted code which is known to cause issues.

Notes

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
@aviemet
Copy link

aviemet commented Feb 10, 2023

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.

@ZhengRui
Copy link

having the same issue, anyone found a solution?

@Swatinem
Copy link
Owner

dts is an object with a key called default 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?

@sidonaldson
Copy link

This seems to work plugins: [dts.default()]

@Coin0804
Copy link

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?

@SokuRitszZ
Copy link

It works using [dts.default()]

@revelt
Copy link

revelt commented May 13, 2023

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!

@Grapdevs
Copy link

Grapdevs commented Jun 1, 2023

It is working with dts.default() ,

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

Successfully merging a pull request may close this issue.

8 participants