Skip to content

[3.0.2] ESM issues: no type:module and wrong import paths #273

@jlowcs

Description

@jlowcs

The library is currently not working with node.js, for 2 reasons:

  1. the package.json is missing type: module, resulting in this kind of error:
          Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/.pnpm/typesense-instantsearch-adapter@3.0.2_@babel+runtime@7.29.2/node_modules/typesense-instantsearch-adapter/lib/Configuration' imported from .../node_modules/.pnpm/typesense-instantsearch-adapter@3.0.2_@babel+runtime@7.29.2/node_modules/typesense-instantsearch-adapter/lib/TypesenseInstantsearchAdapter.js
              at finalizeResolution (node:internal/modules/esm/resolve:274:11)
              at moduleResolve (node:internal/modules/esm/resolve:864:10)
              at defaultResolve (node:internal/modules/esm/resolve:990:11)
              at #cachedDefaultResolve (node:internal/modules/esm/loader:757:20)
              at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:793:38)
              at ModuleLoader.resolveSync (node:internal/modules/esm/loader:816:52)
              at #cachedResolveSync (node:internal/modules/esm/loader:776:25)
              at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:474:50)
              at #link (node:internal/modules/esm/module_job:447:34)
              at new ModuleJobSync (node:internal/modules/esm/module_job:420:17)

That is because the library is using import statements but is not flagged as ESM in package.json.

I tried adding type: module, and it fixed that error, but revealed a second issue.

  1. ESM imports should include the extension and the library uses paths without extension, resulting in this kind of error:
ERROR in ../../node_modules/.pnpm/typesense-instantsearch-adapter@3.0.2_@babel+runtime@7.29.2/node_modules/typesense-instantsearch-adapter/lib/TypesenseInstantsearchAdapter.js 7:1-48
  × Module not found: Can't resolve './Configuration' in '.../node_modules/.pnpm/typesense-instantsearch-adapter@3.0.2_@babel+runtime@7.29.2/node_modules/typesense-instantsearch-adapter/lib'
   ╭─[7:0]
 5 │ import _createClass from "@babel/runtime/helpers/createClass";
 6 │ import _regeneratorRuntime from "@babel/runtime/regenerator";
 7 │ import { Configuration } from "./Configuration";
   · �[35;1m────────────────────────────────────────────────
 8 │ import { SearchClient as TypesenseSearchClient } from "typesense";
 9 │ import { SearchRequestAdapter } from "./SearchRequestAdapter";
   ╰────
  help: Did you mean './Configuration.js'?
        
        The request './Configuration' failed to resolve only because it was resolved as fully specified,
        probably because the origin is strict EcmaScript Module,
        e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"'.
        
        The extension in the request is mandatory for it to be fully specified.
        Add the extension to the request.

I also tried adding the extensions to all relative imports, and it did fix the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions