elm-concurrent-task icon indicating copy to clipboard operation
elm-concurrent-task copied to clipboard

Bug: Invalid ESM code in npm package

Open marvinhagemeister opened this issue 7 months ago • 0 comments

This was original reported here https://github.com/denoland/deno/issues/29013 . It turns out that this npm package ships with invalid ESM code which fails to load in both Node and Deno.

Steps to reproduce

  1. Run npm init -y && npm i @andrewmacmurray/elm-concurrent-task
  2. Create a file foo.mjs (not the .mjs extension) with this content:
import * as ConcurrentTask from "@andrewmacmurray/elm-concurrent-task";
console.log(ConcurrentTask)
  1. Run node foo.mjs -> error

Error:

$ node foo.mjs   
node:internal/modules/esm/resolve:275
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/project/node_modules/@andrewmacmurray/elm-concurrent-task/lib/mjs/http/fetch' imported from /project/node_modules/@andrewmacmurray/elm-concurrent-task/lib/mjs/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:275:11)
    at moduleResolve (node:internal/modules/esm/resolve:860:10)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:780:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:704:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:687:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:305:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:137:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///project/node_modules/@andrewmacmurray/elm-concurrent-task/lib/mjs/http/fetch'
}

Node.js v23.11.0

Cause

The reason this error occurs is because the code in the ./lib/mjs folder is not valid ESM. The syntax is correct, but the specifiers are not. The specifiers leave out the extension which is valid in CommonJS, but not ESM.

// ./lib/mjs/index.mjs
import * as fetchAdapter from "./http/fetch"; // <-- WRONG: invalid ESM, missing extension
// ...

marvinhagemeister avatar Apr 23 '25 11:04 marvinhagemeister