cubing / cubing.js

🛠 A library for displaying and working with twisty puzzles. Also currently home to the code for Twizzle.
https://js.cubing.net/cubing/
GNU General Public License v3.0
232 stars 42 forks source link

[cubing.js issue] Unable to build React project with Vite #301

Closed maxidragon closed 7 months ago

maxidragon commented 7 months ago

Steps to reproduce the issue

  1. Create new React+TypeScript project using npm create vite@latest
  2. Install cubing.js library using npm install cubing
  3. Paste this code in 'src/App.tsx'
    
    import { useState, useEffect } from 'react'
    import './App.css'
    import { randomScrambleForEvent } from "cubing/scramble";

function App() { const [count, setCount] = useState(0) const [scramble, setScramble] = useState("");

useEffect(() => { const generateScramble = async () => { const scr = await randomScrambleForEvent("333"); setScramble(scr.toString());
}; generateScramble(); }, []);

return ( <>

{scramble}

</>

) }

export default App

4. Try to build project with `npm run build` and get error

### Observed behaviour

Running `npm run build` raises error:

transforming (58) node_modules/cubing/dist/lib/cubing/chunks/puzzles-dynamiUnexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit: (commonjs--resolver) resolveId "../chunks/chunk-ZJWG2BON.js" "/home/mgala/test/vite-project/node_modules/cubing/dist/lib/cubing/scramble/index.js" (vite:worker-import-meta-url) transform "/home/mgala/test/vite-project/node_modules/cubing/dist/lib/cubing/chunks/chunk-ZJWG2BON.js" (commonjs--resolver) resolveId "./chunk-ZJWG2BON.js" "/home/mgala/test/vite-project/node_modules/cubing/dist/lib/cubing/chunks/search-dynamic-solve-4x4x4-J2CC72NW.js" error during build: Error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit: (commonjs--resolver) resolveId "../chunks/chunk-ZJWG2BON.js" "/home/mgala/test/vite-project/node_modules/cubing/dist/lib/cubing/scramble/index.js" (vite:worker-import-meta-url) transform "/home/mgala/test/vite-project/node_modules/cubing/dist/lib/cubing/chunks/chunk-ZJWG2BON.js" (commonjs--resolver) resolveId "./chunk-ZJWG2BON.js" "/home/mgala/test/vite-project/node_modules/cubing/dist/lib/cubing/chunks/search-dynamic-solve-4x4x4-J2CC72NW.js" at process.handleBeforeExit (file:///home/mgala/test/vite-project/node_modules/rollup/dist/es/shared/node-entry.js:25902:28) at Object.onceWrapper (node:events:630:26) at process.emit (node:events:515:28)



### 🖼 Screenshots

_No response_

### Expected behaviour

No error

### Environment

I tried building on 3 diffrent node versions, 18, 19 and 21.

### Additional info

_No response_
lgarron commented 7 months ago

Unfortunately, while we put a lot of effort into writing standard interoperable code, Vite has made some choices that are incompatible. For information and workarounds, see:

https://github.com/cubing/cubing.js/issues/296 https://github.com/vitejs/vite/issues/14499#issuecomment-1740267849