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

Can't use webpack with matrix-js-sdk #4392

Open
Harm-van-Stekelenburg opened this issue Sep 6, 2024 · 3 comments
Open

Can't use webpack with matrix-js-sdk #4392

Harm-van-Stekelenburg opened this issue Sep 6, 2024 · 3 comments

Comments

@Harm-van-Stekelenburg
Copy link

I can't get the latest release candidate to work with webpack. Now I'm not a javascript expert so this could very well be me overlooking something basic.

I made a small project to reproduce the issue: https://github.com/Harm-van-Stekelenburg/import_webpack__matrix_js

I run into two problems with this project:

  1. When running npm run serve I get the error:
ERROR in ./node_modules/matrix-js-sdk/lib/client.js 1111:29-52
Module not found: Error: Can't resolve './rust-crypto' in '<project dir>/node_modules/matrix-js-sdk/lib'
  1. If I comment out that line in ./node_modules/matrix-js-sdk/lib/client.js it will build but I get the following error in the browser console:
Uncaught ReferenceError: global is not defined
    qh matrix.js:116
    Vh matrix.js:134
    9820 index.js:2
    Webpack 3

I think that means the global here: https://github.com/matrix-org/matrix-js-sdk/blob/develop/src/matrix.ts#L133

I get neither error on version 34.3.1.

I can fix the second problem with the webpack define plugin to redefine global to something like window but that seems a bit unnecessary.

@Johennes
Copy link
Contributor

Johennes commented Sep 9, 2024

Looks like this might need an additional /index.ts on https://github.com/matrix-org/matrix-js-sdk/blob/develop/src/client.ts#L2252. Interestingly this didn't seem to trigger when we fixed #4287 though.

CC @richvdh.

@Johennes
Copy link
Contributor

Johennes commented Sep 9, 2024

Interestingly this didn't seem to trigger when we fixed #4287 though.

Ah, small wonder. The node example doesn't use encryption. 🤦‍♂️

@Johennes
Copy link
Contributor

Johennes commented Sep 9, 2024

Looks like rewriteImportExtensions doesn't currently support dynamic imports. So this is blocked on babel/babel#16750.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants