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 resolve './rust-crypto' in '<project dir>/node_modules/matrix-js-sdk/lib' with webpack #4392

Closed
Harm-van-Stekelenburg opened this issue Sep 6, 2024 · 5 comments · Fixed by #4445

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.

@saul-jb
Copy link
Contributor

saul-jb commented Oct 8, 2024

@Harm-van-Stekelenburg, I have run into the same problem in the node esm environment and opened a PR to fix it: #4445

I have been adding the following command to my Dockerfile to fix it after building - perhaps you can do something similar for now.

sed -i 's|import("\./rust-crypto")|import("\./rust-crypto/index.js")|' ./node_modules/matrix-js-sdk/lib/client.js

@richvdh richvdh changed the title Can't use webpack with matrix-js-sdk Can't resolve './rust-crypto' in '<project dir>/node_modules/matrix-js-sdk/lib' with webpack Oct 8, 2024
@richvdh
Copy link
Member

richvdh commented Oct 8, 2024

I've updated the title to focus this issue on the first problem in the original description. Please open another issue for the second problem, if it's still a thing (the link no longer goes to a line that references global)

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

Successfully merging a pull request may close this issue.

4 participants