Skip to content

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

Open
@daenub

Description

@daenub

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn’t working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions