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

[BUG] ESM support is broken #357

Open
frozenbonito opened this issue Jun 27, 2024 · 1 comment
Open

[BUG] ESM support is broken #357

frozenbonito opened this issue Jun 27, 2024 · 1 comment
Assignees
Labels

Comments

@frozenbonito
Copy link

Describe the bug

An error occurs when importing crossnote in ESM.

Environment

  • OS: WSL2 (Debian11)
  • Crossnote: 0.9.9
  • Node.js: 20.15.0

To Reproduce

index.js (It is a copy of example code in README.md)

import { Notebook } from "crossnote";

async function main() {
  const notebook = await Notebook.init({
    notebookPath: "/absolute/path/to/your/notebook",
    config: {
      previewTheme: "github-light.css",
      mathRenderingOption: "KaTeX",
      codeBlockTheme: "github.css",
      printBackground: true,
      enableScriptExecution: true, // <= For running code chunks.
    },
  });

  // Get the markdown engine for a specific note file in your notebook.
  const engine = notebook.getNoteMarkdownEngine("README.md");

  // open in browser
  await engine.openInBrowser({ runAllCodeChunks: true });

  // html export
  await engine.htmlExport({ offline: false, runAllCodeChunks: true });

  // chrome (puppeteer) export
  await engine.chromeExport({ fileType: "pdf", runAllCodeChunks: true }); // fileType = 'pdf'|'png'|'jpeg'

  // prince export
  await engine.princeExport({ runAllCodeChunks: true });

  // ebook export
  await engine.eBookExport({ fileType: "epub" }); // fileType = 'epub'|'pdf'|'mobi'|'html'

  // pandoc export
  await engine.pandocExport({ runAllCodeChunks: true });

  // markdown(gfm) export
  await engine.markdownExport({ runAllCodeChunks: true });

  return process.exit();
}

main();

Running index.js, ERR_MODULE_NOT_FOUND occurs.

$ node index.js
node:internal/modules/run_main:129
    triggerUncaughtException(
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/frozenbonito/crossnote-repro/node_modules/bit-field/lib/render' imported from /home/frozenbonito/crossnote-repro/node_modules/crossnote/out/esm/index.mjs
Did you mean to import "bit-field/lib/render.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:265:11)
    at moduleResolve (node:internal/modules/esm/resolve:933:10)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///home/frozenbonito/crossnote-repro/node_modules/bit-field/lib/render'
}

Node.js v20.15.0

Expected behavior
It succeeds.

@janreppien
Copy link

Are there any updates on this issue? I would like to use crossnote in a nuxt.js application and can not use require.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants