Closed michaelfranzl closed 6 months ago
@marklundin - any idea here?
Hey @michaelfranzl, thanks for flagging this and the detailed repro.
Great catch. It looks like the engine was updated in 1.66.0 to use type module in the package.json https://github.com/playcanvas/engine/blob/d75dba58a5ca60178f31d4a9c7e5bcb094e75eb3/package.json#L24
My understanding is that if the type is a module, then Node expects `main' to be a ES module, which it actually is not.
For the time being, you should be able to directly import the ES6 build using import { Vec3 } from 'playcanvas/build/playcanvas.mjs'
which will fix your issue. But we'll need to update our side to correctly handle this.
It looks like we can fix this by including an exports field
"exports": {
".": {
"import": "./build/playcanvas.mjs",
"require": "./build/playcanvas.js"
}
},
This looks like the recommended approach for Node > 10 https://nodejs.org/api/packages.html#package-entry-points. Any thoughts @epreston @mvaligursky @kungfooman @kpal81xd
Yep that looks fine to me had a similar issue with exports for react on PCUI. Ill make a PR to add that change
Yep, I think we still need the existing main
and modules
fields for older versions of Node, but this should at least "feature detect" if import is available
Description
I'm using Playcanvas in SvelteKit. This works well up until Playcanvas v1.65.5 but stops working when upgrading to the following release of Playcanvas, which is v1.66.0 (and newer).
Steps to Reproduce
The issue is reproducible with minimal effort.
Using Node.js v20.11.1 LTS, create a new SvelteKit application:
In the file
src/routes/+page.svelte
import Playcanvas and instantiate aVec3
:Save the file and start the server:
Access the URL printed in the terminal (either using browser or using curl/wget).
Vite immediately crashes with the following messages:
I tested with Vite v4.5 and current (v5.0) and @sveltejs/kit v1.27 and current (v2.0), with the same results.