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

Cubing.js not working with vite #192

Closed
debater-coder opened this issue Jul 10, 2022 · 4 comments · Fixed by #193
Closed

Cubing.js not working with vite #192

debater-coder opened this issue Jul 10, 2022 · 4 comments · Fixed by #193

Comments

@debater-coder
Copy link
Contributor

debater-coder commented Jul 10, 2022

Scroll down to the third post in this thread to see the location of the issue, and the fourth post for a workaround

To Reproduce
Steps to reproduce the behavior:

  1. Create a new vanilla TypeScript project with vite.
  2. Install cubing.js
  3. Import cubing.js in index.ts
  4. Restart dev server

Vite throws this error:

          ✘ [ERROR] Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
          
              node_modules/cubing/dist/esm/chunk-TB6NTLZY.js:578:10:
                578 │   let r = 1n;
                    ╵           ~~
          
          ✘ [ERROR] Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
          
              node_modules/cubing/dist/esm/chunk-TB6NTLZY.js:949:12:
                949 │     let n = 1n;
                    ╵             ~~
          
          ✘ [ERROR] Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
          
              node_modules/cubing/dist/esm/chunk-TB6NTLZY.js:1808:13:
                1808 │     let sz = 1n;
                     ╵              ~~
          
          ✘ [ERROR] Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
          
              node_modules/cubing/dist/esm/chunk-TB6NTLZY.js:1811:11:
                1811 │       sz = 1n;

Expected behavior
cubing.js is imported.

Browser:

  • OS: Windows 11
  • Browser Chrome/Edge 103

Screenshots
image

@debater-coder
Copy link
Contributor Author

debater-coder commented Jul 10, 2022

npm run build also fails.
Hopefully this gives more info as to the location of the bug.

Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
573|  }
574|  function factorial(a) {
575|    let r = 1n;
   |            ^
576|    while (a > 1) {
577|      r *= BigInt(a);

Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
944|    }
945|    reassemblySize() {
946|      let n = 1n;
   |              ^
947|      for (let i = 0; i < this.orbitdefs.length; i++) {
948|        n *= this.orbitdefs[i].reassemblySize();

Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
1803|      }
1804|      let none = 0;
1805|      let sz = 1n;
   |               ^
1806|      for (let i = 0; i < g.length; i++) {
1807|        knutha(n - 1, g[i], 1);

Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
1806|      for (let i = 0; i < g.length; i++) {
1807|        knutha(n - 1, g[i], 1);
1808|        sz = 1n;
   |             ^
1809|        let tks = 0;
1810|        let sollen = 0;

@debater-coder
Copy link
Contributor Author

debater-coder commented Jul 10, 2022

OK, I have found the location of one of those functions.

In src/cubing/puzzle-geometry/Perm.ts on line 45, there is this function which uses a BigInt literal.

export function factorial(a: number): bigint {
  let r = 1n;
  while (a > 1) {
    r *= BigInt(a);
    a--;
  }
  return r;
}

This is what is causing the failing build in vite. We can either change it to not use BigInt or we can leave it alone and add a warning in the documentation to change the build targets.

@debater-coder
Copy link
Contributor Author

I have found a workaround for this in vite. The build fails because the default build target is es2019. To get this to work, put this in your vite.config.ts:

import {UserConfig} from "vite";

const config: UserConfig = {
    build: {
        target: "es2020"
    }
}

export default config

@debater-coder
Copy link
Contributor Author

IMO its impractical to change this to not use BigInt so I think we should just put this workaround on the README and more generally specify that cubing.js requires a build target of at least es2020 to work. I will submit a pull request for this.

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

Successfully merging a pull request may close this issue.

1 participant