Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

331
Views
Error exporting my TypeScript NPM package

I'm trying to import my NPM package I made, but I keep getting this error:

Error: Cannot find module '/Users/…/project/node_modules/@my-package/lib/rehype-toc' imported from /Users/.../project/node_modules/@my-package/lib/index.js.

For the life of me, I cannot figure out why I'm getting this error. Everything seems like it should work since my lib/rehype-toc file is exporting a function and the file is actually there inside the lib folder. It's not missing.

Importing my package in NextJS

import rehypeToc from '@my-package';

Package Setup

package.json

// ...
"main": "lib/index.js",
"type": "module",
"types": "lib/index.d.ts",
"files": [
  "lib"
],

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "lib": ["ES2020"],
    "module": "ES2020",
    "moduleResolution": "node",

    "outDir": "lib",
    "sourceMap": true,
    "declaration": true,

    "typeRoots": [
      "node_modules/@types",
      "src/typings"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "test/**/*.js"
  ]
}

lib/index.js

import { toc } from "./rehype-toc";
export * from "./types";
export { toc };
// Export `toc` as the default export
export default toc;
//# sourceMappingURL=index.js.map

lib/index.d.ts

import { toc } from "./rehype-toc";
export { CssClasses, InsertPosition, Options } from "./options";
export * from "./types";
export { toc };
export default toc;

lib/rehype-toc.js

import { createTOC } from "./create-toc";
import { customizationHooks } from "./customization-hooks";
import { findHeadings } from "./find-headings";
import { findMainNode } from "./find-main-node";
import { insertTOC } from "./insert-toc";
import { NormalizedOptions } from "./options";

export function toc(opts) {
  // ...
}

Any help would be greatly appreciated.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!