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

[rehype-notion] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in #83

Open
zirkelc opened this issue Feb 26, 2023 · 3 comments

Comments

@zirkelc
Copy link

zirkelc commented Feb 26, 2023

I try to get rehype-notion to work, but always get the error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/zirkelc/Code/html-to-notion/node_modules/rehype-notion/package.json imported from /Users/zirkelc/Code/html-to-notion/rehype-notion.js
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:641:13)
    at packageResolve (node:internal/modules/esm/resolve:872:14)
    at moduleResolve (node:internal/modules/esm/resolve:938:20)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

That's the JS code:

import { unified } from 'unified'
import { parse } from 'rehype-parse'
import { rehypeNotion } from 'rehype-notion'

const html = `
  <h1>Heading</h1>
  <p>Paragraph</p>
`


const vfile = await unified()
	.use(parse)
	.use(rehypeNotion)
	.process(html);

const notionBlocks = vfile.result
console.log(notionBlocks)

The package.json of rehype-notion seems to miss an export definition for import since its a ESM package. However, adding that export didn't solve the issue:

  "exports": {
    ".": {
      "import": "./src/index.js",
      "require": "./src/index.js"
    }
  },

It then fails with this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/zirkelc/Code/html-to-notion/node_modules/.pnpm/[email protected]_hjujqg5lc3gpvhzaa4sfejxtk4/node_modules/rehype-notion/src/lib/rehype-notion' imported from /Users/zirkelc/Code/html-to-notion/node_modules/.pnpm/[email protected]_hjujqg5lc3gpvhzaa4sfejxtk4/node_modules/rehype-notion/src/index.js
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:326:11)
    at moduleResolve (node:internal/modules/esm/resolve:945:10)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Any idea what might be wrong here?

@tefkah
Copy link
Member

tefkah commented Mar 10, 2023

hi, thanks for the bug report! i think there was something wrong with the package description, I recently reworked it, could you check if it works for you now?

@tefkah
Copy link
Member

tefkah commented Mar 10, 2023

Also, rehype-parse and rehype-notion do not have a named export, the code should look like this (this works for me)

// @ts-check
import { unified } from 'unified'
import parse from 'rehype-parse'
import rehypeNotion from 'rehype-notion'

const html = `
  <h1>Heading</h1>
  <p>Paragraph</p>
`


const vfile = await unified()
    .use(parse)
    .use(rehypeNotion)
    .process(html);

const notionBlocks = vfile.result
console.log(notionBlocks)

@tefkah
Copy link
Member

tefkah commented Mar 10, 2023

edit: just saw that you literally took the example out of the README, my bad! I will update it

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

No branches or pull requests

2 participants