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

build: "Cannot find module" when using exported modules #1916

Open
daenub opened this issue Jan 30, 2025 · 0 comments
Open

build: "Cannot find module" when using exported modules #1916

daenub opened this issue Jan 30, 2025 · 0 comments
Labels
bug Something isn’t working

Comments

@daenub
Copy link

daenub commented Jan 30, 2025

Error message

render /chart.js →
Unexpected error: Cannot find module 'lit@3.2.1/index.js'
Require stack:
- /…/hello-framework/src/noop.js
The full error follows

node:internal/modules/cjs/loader:1048
  const err = new Error(message);
              ^

Error: Cannot find module 'lit@3.2.1/index.js'
Require stack:
- /…/hello-framework/src/noop.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Function.resolve (node:internal/modules/helpers:136:19)
    at resolveNodeImportInternal (file:///…/hello-framework/node_modules/@observablehq/framework/dist/node.js:27:35)
    at resolveNodeImport (file:///…/hello-framework/node_modules/@observablehq/framework/dist/node.js:21:10)
    at getModuleStaticImports (file:///…/hello-framework/node_modules/@observablehq/framework/dist/resolvers.js:386:23)
    at async renderModule (file:///…/hello-framework/node_modules/@observablehq/framework/dist/render.js:177:19)
    at async Module.build (file:///…/hello-framework/node_modules/@observablehq/framework/dist/build.js:309:22)
    at async file:///…/hello-framework/node_modules/@observablehq/framework/dist/bin/observable.js:87:7 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/…/hello-framework/src/noop.js' ]
}
Node.js v20.9.0

Description

When I use a node import inside an exported module and run the build script i get the error above.

In this example i installed and used the shoelace library "@shoelace-style/shoelace": "^2.19.1". I'm using version 1.13.2 of Framework.
I was able to reproduce the error with other packages as well. In case of our private chart library e.g. it was d3 that couldn't be found.

dynamicPaths is configured as follows:

{
  dynamicPaths: ["/chart.js"],
}

The src/chart.js has the following content:

import "@shoelace-style/shoelace/dist/components/input/input.js";
import { html } from "htl";

export function Chart() {
  return html`<sl-input label="Hello world"></sl-input>`;
}

The issue only appears when chart.js is defined as an exported module.
If i import the Chart function into a markdown file and use it there, then the build process runs successfully.

I hope this is enough information to reproduce the bug.

@daenub daenub added the bug Something isn’t working label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

No branches or pull requests

1 participant