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

Vue 3 Documentation #3383

Closed
salviof opened this issue May 18, 2023 · 2 comments
Closed

Vue 3 Documentation #3383

salviof opened this issue May 18, 2023 · 2 comments

Comments

@salviof
Copy link

salviof commented May 18, 2023

Thats not easy install matrix-js-sdk in a vue project.
with this simple import as
import * as sdkMatrix from 'matrix-js-sdk';

With this simple import, used in the Node documentation examples, we got this error:

"crypto.ts:19 Uncaught ReferenceError: global is not defined
at node_modules/matrix-js-sdk/lib/crypto/crypto.js (crypto.ts:19:12)"

maybe, in example folder shoud have a VUE 3 example,vue adopts a good architecture for creating reactive UIs ideal for chat applications.

@salviof salviof closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2023
@SubCube
Copy link

SubCube commented Aug 7, 2023

@salviof how you solved it?

@simaotwx
Copy link

simaotwx commented Nov 14, 2023

Install @vitejs/plugin-legacy.

Add this to the plugin section in vite.config.js:

    // https://github.com/vitejs/vite/discussions/7915#discussioncomment-3910940
    legacy({
      targets: ['chrome >= 64', 'edge >= 79', 'safari >= 11.1', 'firefox >= 67'],
      ignoreBrowserslistConfig: true,
      renderLegacyChunks: false,
      /**
       * Polyfills required by modern browsers
       *
       * Since some low-version modern browsers do not support the new syntax
       * You need to load polyfills corresponding to the syntax to be compatible
       * At build, all required polyfills are packaged according to the target browser version range
       * But when the page is accessed, only the required part is loaded depending on the browser version
       *
       * Two configuration methods:
       *
       * 1. true
       *  - Automatically load all required polyfills based on the target browser version range
       *  - Demerit: will introduce polyfills that are not needed by modern browsers in higher versions,
       *    as well as more aggressive polyfills.
       *
       * 2、string[]
       *  - Add low-version browser polyfills as needed
       *  - Demerit: It needs to be added manually, which is inflexible;
       *    it will be discovered after the production is deployed, resulting in production failure! ! !
       */
      modernPolyfills: ['es/global-this'],
      //  or
      // modernPolyfills: true,
    }),

Add this to the top of your main.ts or main.js:

window.global = globalThis

That will fix it

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

No branches or pull requests

3 participants