Provide asm.js compiled assets in npm package #444
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'd like to use yoga to handle svg positioning + generation from a browser similar to this
http://blog.scottlogic.com/2015/02/02/svg-layout-flexbox.html
I was expecting to be able to install the yoga-layout npm package and
Providing the asm.js bundled library could also help to implement #419
The asm.js build should already be distributed along with the npm package. You just have to use
require("yoga-layout")
, and your bundler will pick the right build (because of this line).@arcanis I dont seem to find asm.js as part of the npm package. I have installed it on window 10 using these steps
I had built svg layout engine called placard which uses yoga-layout internally for generating dynamic svg layouts. Yes, it is inspired by scottlogic post from Colin Eberhard.
I hope, it could be of some help to the javascript/node community
I just checked and the asm.js build is in the latest release:
Closing as it seems to be there. I'll also make a new release this Friday. Re-open if you still have issues after that 👍
Should it also work in a browser ? Webpack answers with an error:
That's weird - the build shouldn't need the
fs
module. Maybe a debugfopen
symbol or similar has been left unguarded?Found such code
...var nodeFS=require("fs");var nodePath=require("path")...
innode_modules/yoga-layout/build/Release/nbind.js
@arcanis btw, Does it make sense to use yoga in a browser if a browser has native css flexbox support ? what are the prose if does ?
Yeah its useful at times in the browser :) for example if building webgl experiences.
What about DOM layout based on yoga ?
Possibly, i'm not the right person to know that though
I've spent a week trying to get this library working in the browser with no luck :(
I've got the same issues that it
Can't resolve 'fs'
in nbind.js . But after manually taking out the node code it fails withUncaught TypeError: Cannot read property 'slice' of null
, becausevar sourceRegex = /^function\s*\(([^)]*)\)\s*{\s*([^*]*?)[\s;]*(?:return\s*(.*?)[;\s]*)?}$/;
fails to parse the functions its used on.After looking into that, it seems webpack/babel added names to the anonymous functions cause they weren't in the source and the regex doesn't parse functions with names. After fixing that I'm stuck at this one :
Uncaught ReferenceError: _a is not defined
from_a = _typeModule(_typeModule), _nbind.Type = _a.Type, _nbind.makeType = _a.makeType, _nbind.getComplexType = _a.getComplexType, _nbind.structureList = _a.structureList;
I suspect a lot of the problems are due to babel mangling things, but I've been trying for hours to figure out how to load a script as is w/o running it through babel-loader, and I can't find what I need.
Has anyone gotten this to work using webpack and got a solution for the require('fs') issue to start with?
As well, are there any actually working examples/tests that you have to validate that this works in the browser as published? And works by using require('yoga-layout')?
I'll have a look at this before making the 1.5 release this coming week.
I fixed the
require('fs')
issue. Just addedto the webpack config and it works in my TypeScript + webpack env. Also i can instruct how to generate typescript typings for the yoga if necessary ;)
The lib works like a charm in DOM. Here is how I render layouted elements:
The only issue to me right now is very small javascript documentation ;(
Awesome! Yeah docs are sorely lacking. We would be very greatfull if you helped us out on that front as you are using it :)
I will try to share some source with basic layouts later
Bah! Moving back to the code in node_modules with your fs: 'empty' fixes things. Looks like all the other issues were symptoms of working on the code locally.
I now have it loading in the browser finally! Only a bunch of weird warnings about it parsing the .hh and .cc files still left to go.
Thanks for the help!
Also as another example of using this lib in the browser, I'm trying to use this to position svg elements within react, where each component starts with
<g>
and a transform for the position. So this lib is super useful for me. Thanks.I think my original issue would have been resolved by the
fs: 'empty'
andmodule: 'empty'
.Because I was getting errors resolving .cc and .hh files I assumed that the default entry point of the module mustn't have been the browser version.
I eventually got emscripten and llvm working on my machine and realised that I got the same error messages when I manually compiled yoga for the browser.
I did also find this library on npm that ended up working for the demo I was creating.
I figured out the .hh/.cc errors were from a dynamic require expression that tried to parse all the files in the same dir (#535), so hopefully that should be cleaned up for the next release.
Oh, I see. By any chance, would you be using Webpack 2? I used the asmjs release with Webpack 3, but didn't notice the error before. It's possible the "static backtick strings" support has only been added recently.
I've been using webpack 1, so perhaps they've fixed things in the newest versions.
@chrisregnier I came across similar issues to you regarding babel and adding
"ignore": [ "node_modules/yoga-layout" ]
to.babelrc
resolved the issue for me.I'm trying to use the
yoga-layout
package in my app using TypeScript and Rollup. I deleted thenode_modules
folder, did anode-gyp rebuild
in both the package's and my own directories, andnpm rebuild
, but I still get this same error in the Chrome JS console every time:It seems to not be looking in the
yoga-layout
package folder for the bindings, and instead looking at my project's code. Any ideas regarding what's going on here?Found that indeed the asmjs build is included with the npm package (
v1.6.0
), but it produces the following error when imported using node v8.5.0 and npm v5.4.0:I was able to solve the issue by compiling the asmjs script locally via
npm run build:browser
using emscriptenv1.37.21
and the latest xcode command line tools (Apple LLVM version 9.0.0 (clang-900.0.37)
). It produced the following file: https://gist.github.com/larsonjj/577c943f3a1ab7337c42940addf31270If you replace your
node_modules/yoga-layout/build/Release/nbind.js
file with the linked gist above, it should alleviate the issues withfs
andpath
imports.This leads me to believe that the next asmjs build included in the npm package needs to be produced using the latest emscripten version to fix the problem going forward.
Yoga is useful for doing flexbox layout in SVG.
I ran into the
_a is not defined
error mentioned above and ended up just correcting the offending line. Everything worked after that. Have not tried a later emscripten yet.@NickGerleman Could we begin providing the asm.js exports again? It would be pretty easy to begin distributing the asm.js versions again right? I'm running react-native and a library I'm consuming uses yoga-layout. I know it's weird since obviously there are native bindings to yoga in the project, but the library I'm consuming knows nothing about them. If we just could have the asm.js bindings back, the library would be happy. And in a RN environment, the code should execute at near native speeds as well since the asm.js will ultimately get compiled to Hermes bytecode (see https://github.com/facebook/hermes/issues/429)
I could take a whack at adding this back if there's no opposition from the maintainers