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

matrix-js-sdk no longer works in node #4287

Open
richvdh opened this issue Jun 26, 2024 · 2 comments
Open

matrix-js-sdk no longer works in node #4287

richvdh opened this issue Jun 26, 2024 · 2 comments
Labels
A-Developer-Experience O-Occasional Affects or can be seen by some users regularly or most users rarely S-Major Severely degrades major functionality or product features, with no satisfactory workaround T-Defect

Comments

@richvdh
Copy link
Member

richvdh commented Jun 26, 2024

#4284 describes a problem wherein matrix-js-sdk no longer works in a CommonJS environment, but actually it's worse than that: it doesn't work in an ES modules environment either.

If we apply the fix from #4285, and run in an esm environment, I get:

node:internal/modules/esm/resolve:260
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/rav/work/matrix-js-sdk/examples/node/node_modules/matrix-js-sdk/lib/matrix' imported from /home/rav/work/matrix-js-sdk/examples/node/node_modules/matrix-js-sdk/lib/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:260:11)
    at moduleResolve (node:internal/modules/esm/resolve:920:10)
    at defaultResolve (node:internal/modules/esm/resolve:1119:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:542:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:511:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:126:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///home/rav/work/matrix-js-sdk/examples/node/node_modules/matrix-js-sdk/lib/matrix'
}

Node.js v22.2.0

The problem appears to be that index.js contains:

import * as matrixcs from "./matrix";

However, the file it actually wants is ./matrix.js, and the nodejs ESM resolver doesn't know it needs to add the extension. Likewise for every link in the project :/

@richvdh
Copy link
Member Author

richvdh commented Jun 26, 2024

Apparently, the typescript way to do this is actually to

import {foo} from "./matrix.js"`; // note js extension

The .js is then retained in the output, but typescript is intelligent enough to use the ts file for type definitions (cf https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution)

@dbkr dbkr added O-Occasional Affects or can be seen by some users regularly or most users rarely S-Major Severely degrades major functionality or product features, with no satisfactory workaround labels Jul 3, 2024
@0ctoPusK
Copy link

0ctoPusK commented Jul 4, 2024

I got the same error as you had

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Developer-Experience O-Occasional Affects or can be seen by some users regularly or most users rarely S-Major Severely degrades major functionality or product features, with no satisfactory workaround T-Defect
Projects
None yet
Development

No branches or pull requests

3 participants