Server doesnt start - Vite 3 plugin compression require() of ES Module

Hi, trying to debug my setup here after failing to get needle to run a server from the editor.
I had it working before with 2021 LTS , but not sure thats the issue.

Node version is v16.17.1
npm is 8.15.0

I am following Option 3 from the getting started guide (btw there it says 'we support 2020.3 and 2022 '- not ‘Unity 2020.3.16+, 2021.3+ or 2022.2+’ )

After creating a new project from Unity Hub, the 3D Core template, and opening it, I add the registry to Package manager and install the Needle Engine Exporter.
I don’t create a new scene from the templates at this point but skip to the Create a new scene from Scratch guide needle-engine-support/documentation/getting-started.md at main · needle-tools/needle-engine-support · GitHub , since I am already in a new project that Unity Hub just created. Then I add a new empty game object and add the Export Info component to it. I click Generate and then node.js opens in a window and reports this error

Original Post on Discord

by user 540540751424258048

failed to load config from G:\UnityStuff\needletools\WillItWork\Projects\SampleScene\vite.config.js error when starting dev server: Error [ERR_REQUIRE_ESM]: require() of ES Module G:\UnityStuff\needletools\WillItWork\Projects\SampleScene\node_modules\vite-plugin-compression\dist\index.mjs not supported. Instead change the require of G:\UnityStuff\needletools\WillItWork\Projects\SampleScene\node_modules\vite-plugin-compression\dist\index.mjs to a dynamic import() which is available in all CommonJS modules. at Object.<anonymous> (G:\UnityStuff\needletools\WillItWork\Projects\SampleScene\vite.config.js:34:46) at Object._require.extensions.<computed> [as .js] (file:///G:/UnityStuff/needletools/WillItWork/Projects/SampleScene/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:63524:24) at loadConfigFromBundledFile (file:///G:/UnityStuff/needletools/WillItWork/Projects/SampleScene/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:63532:21) at loadConfigFromFile (file:///G:/UnityStuff/needletools/WillItWork/Projects/SampleScene/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:63400:34) at async resolveConfig (file:///G:/UnityStuff/needletools/WillItWork/Projects/SampleScene/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:63017:28) at async createServer (file:///G:/UnityStuff/needletools/WillItWork/Projects/SampleScene/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:62083:20) at async CAC.<anonymous> (file:///G:/UnityStuff/needletools/WillItWork/Projects/SampleScene/node_modules/vite/dist/node/cli.js:700:24)

by user 540540751424258048

Oh right I had that same error a few minutes before too. Its an easy fix, one sec:

in the package.json (in the Projects/SampleScene folder) change the version to "vite-plugin-compression": "^0.5.1"

and then click install again on the ExportInfo component. Should work after that

will be fixed in the template in the next version. Not sure how that could slip through or why it suddenly fails :thinking:

I like your directory names btw (UnityStuff/needletools/WillItWork ^^)

do we have to reload the project?

by user 540540751424258048

ive changed it but i guess it doesnt catch the change

by user 540540751424258048

reloadin!

by user 540540751424258048

you need to click this button
unknown.png

oh interesting

by user 540540751424258048

makes sense now thanks

by user 540540751424258048

(internally it just runs npm install in your web project directory if you’re familiar with that)

After the install has finished you should be able to click play

I guess the first time it worked was because i cloned the repo and just ran the project from Unity Hub (upgraded the project and was fine). But doing this from scratch route and through packagemanager we might have this little problem you fixed

by user 540540751424258048

by user 540540751424258048

Its because the project in the sample repo was created with Vite 2 and since a few versions we upgraded vite to version 3 but seems I didnt test that well enough/was fooled by some caching there too

Hope it works now for you