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 CommonJS environment #4284

Closed
richvdh opened this issue Jun 26, 2024 · 0 comments · Fixed by #4285
Closed

matrix-js-sdk no longer works in CommonJS environment #4284

richvdh opened this issue Jun 26, 2024 · 0 comments · Fixed by #4285
Labels
A-Developer-Experience T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems

Comments

@richvdh
Copy link
Member

richvdh commented Jun 26, 2024

As of #4187, which landed in v33.0.0, matrix-js-sdk is built into an ECMAScript module (ie, one which uses import {foo} from "bar" rather one that uses const {foo} = require("bar")).

This has broken things for people that attempt to import the SDK in a CommonJS environment, including one of our own examples.

Specifically, it results in this error:

(node:55093) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/rav/work/matrix-js-sdk/examples/node/node_modules/matrix-js-sdk/lib/index.js:17
import * as matrixcs from "./matrix";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1350:18)
    at Module._compile (node:internal/modules/cjs/loader:1379:20)
    at Module._extensions..js (node:internal/modules/cjs/loader:1518:10)
    at Module.load (node:internal/modules/cjs/loader:1249:32)
    at Module._load (node:internal/modules/cjs/loader:1065:12)
    at Module.require (node:internal/modules/cjs/loader:1271:19)
    at require (node:internal/modules/helpers:123:16)
    at Object.<anonymous> (/home/rav/work/matrix-js-sdk/examples/node/app.js:3:11)
    at Module._compile (node:internal/modules/cjs/loader:1434:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1518:10)

Node.js v22.2.0
@dosubot dosubot bot added A-Developer-Experience T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems labels Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Developer-Experience T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant