Yoga.Node.create(), Node is undefined
tyutjohn opened this issue · comments
Issues and Steps to Reproduce
When i packaged yoga as commonjs and found the error like this: 'TypeError: Cannot read properties of undefined (reading 'create')'
I will provide a minimal reproduction scenario
/** a.mjs **/
import Yoga from 'yoga-layout/sync'; console.log(Yoga.default.Node.create) console.log(Yoga.Node.create)
Then run node a.mjs
, node version is v16
someone encounters this problem, u can try this
import Yoga from 'yoga-layout/sync'; const Yoga = ((_Yoga as any)?.default ?? (_Yoga as any) ) as typeof _Yoga const createNode = Yoga.Node.create(); ...
How to fix it
But this problem seems to be yoga's packaging configuration issue,I found some examples for reference,
vueuse-package.json
Maybe need to add index.d.mts index.mjs , like this https://www.npmjs.com/package/@vueuse/shared?activeTab=code
ESModule + CommonJS interop strikes again 🥲.
We could export separate variants, but we also already have a pretty big matrix. Need to think about it a bit.
I think I want to make Yoga ES module only, as the forward looking option. Top level await fixes api issues, and puts us closer to being able to take advantage of the final spec for module wasm integration.
If we have top level await, we can do sync api with async compilation, which would also give us a way to do wasm browser build with sync API.
@NickGerleman hey! Any plans to get this fix published? As I understand https://github.com/facebook/yoga/releases/tag/v2.0.1 contains old schema (does not contain fix)
@NickGerleman hey! Any plans to get this fix published? As I understand https://github.com/facebook/yoga/releases/tag/v2.0.1 contains old schema (does not contain fix)
We are planning to do a new major release next month, which will publish the ESModule version.