Skip to content

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

Open

Description

@zirkelc

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/rehype-notion@0.0.1_hjujqg5lc3gpvhzaa4sfejxtk4/node_modules/rehype-notion/src/lib/rehype-notion' imported from /Users/zirkelc/Code/html-to-notion/node_modules/.pnpm/rehype-notion@0.0.1_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?

Activity

  1. tefkah commented on Mar 10, 2023

    @tefkah
    Member

    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?

  2. tefkah commented on Mar 10, 2023

    @tefkah
    Member

    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)
  3. tefkah commented on Mar 10, 2023

    @tefkah
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions