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.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.