Skip to content

Inconsistent ESM adherence causes ERR_MODULE_NOT_FOUND #64

@taylor1791

Description

@taylor1791

When I run npm i solid-swr && node -e 'const {useSwr} = import("solid-swr");' nodejs throws the following error. I experience this error in node 18, 20, and 22. I believe this is because this package uses "type": "module" in package.json, but also ships .js as an extension throughout the dist directory (instead of .mjs). Renaming the appropriate files to .mjs fixes the problem, but this may be undesirable for other reasons.

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/taylor1791/src/tmp/node_modules/solid-swr/dist/core' imported from /home/taylor1791/src/tmp/node_modules/solid-swr/dist/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:257:11)
    at moduleResolve (node:internal/modules/esm/resolve:913:10)
    at defaultResolve (node:internal/modules/esm/resolve:1037:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:650:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:599:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:582:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:241:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:132:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///home/taylor1791/src/tmp/node_modules/solid-swr/dist/core'
}

I discovered this problem while I was using vitest. If any tested file imports solid-swr the same error occurs since vitest appears to follow nodejs' module resolution algorithm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions