Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yoga npm package version 2.0.0-beta.1 doesn't work with Webpack #1321

Closed
1 task done
Omxjep3434 opened this issue Jul 1, 2023 · 5 comments
Closed
1 task done

Yoga npm package version 2.0.0-beta.1 doesn't work with Webpack #1321

Omxjep3434 opened this issue Jul 1, 2023 · 5 comments

Comments

@Omxjep3434
Copy link

Omxjep3434 commented Jul 1, 2023

Report

The new yoga-layout npm package version 2.0.0-beta.1 does not work with Webpack because the compilation environment is recognized as a Node environment, and requiring Node-only modules like 'fs' and 'path' causes Webpack errors.

Issues and Steps to Reproduce

Any Webpack environment can be used, but here is an easy way to reproduce:

Create a fresh project using create-react-app: npx create-react-app yoga-test and then add yoga-layout npm install --save yoga-layout.

Simply add an import statement to a file, such as App.js: import { loadYoga } from "yoga-layout"; and invoke loadYoga: loadYoga().

Start the app: npm run start

You should see a compilation error along the lines of: Module not found: Error: Can't resolve 'fs' in '/path_to_project/node_modules/yoga-layout/binaries'.

Attempts to fix

I can fix the issue in a hacky way by simply deleting the 'if' statement that contains the require statements in node_modules/yoga_layout/binaries/wasm-async.js. The Yoga system does seem to work correctly when I do this, but I have not tested in-depth.

I also attempted to use the node-polyfill-webpack-plugin, but this seems to have no effect and would probably not be a good solution anyway.

What is the correct way to solve this issue?

@NickGerleman
Copy link
Contributor

This is because Emscripten will output “fs” usage in a conditional when told to compile for both Node and web. I thought I had fixed that with another change, but looking at the binary we published, the issue is still there.

A proper fix should come soon, but in the meantime, I think adding the following to your Webpack config might work for Webpack 5:

resolve: {
    fallback: {
        fs: false,
        path: false
    },
},

I think earlier versions of Webpack may polyfill these by default.

@Omxjep3434
Copy link
Author

Thanks Nick! That works great and looking forward to the fix!

NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 11, 2023
Summary: Fixes facebook#1321

Differential Revision: D47368830

fbshipit-source-id: 4a77224e3dc89c06ace3628d48c0235a3932fcfe
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 11, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: D47368830

fbshipit-source-id: 766dec6fbbf356931ecd2e044dad51b8026754e8
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 11, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: D47368830

fbshipit-source-id: f2c97198977033db4fee0fb81539276161d22607
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 11, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: D47368830

fbshipit-source-id: e253ff686bd76863a89dcd331fb86394878a1bd9
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 11, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: D47368830

fbshipit-source-id: ef75d4989245b3df8f9aefb3b313bda3949827d2
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 12, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Reviewed By: cortinico

Differential Revision: D47368830

fbshipit-source-id: 4128366d749ae679b54bd15bec4c398dc08e7663
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 12, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: https://internalfb.com/D47368830

fbshipit-source-id: 889c904c062567f4166a735165bbb33e72180b61
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 12, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: https://internalfb.com/D47368830

fbshipit-source-id: dd6b9e1dc8e6b0dfe7f840f9c9d97571f6b7f8d9
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 12, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: https://internalfb.com/D47368830

fbshipit-source-id: b8d5f80eb624895c418d252a3a17a8c6c0751770
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 12, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: https://internalfb.com/D47368830

fbshipit-source-id: 9fec5c8d7a5de3ec2131ec66ce8d8bd39713b745
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 12, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Reviewed By: cortinico

Differential Revision: D47368830

fbshipit-source-id: 782e7b6a0ba1f461670020b6e93883c39ad49245
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 12, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: https://internalfb.com/D47368830

fbshipit-source-id: 6ef4b6c2bb32da41cf6e8fa2732a3169c6f88026
NickGerleman added a commit to NickGerleman/yoga that referenced this issue Jul 12, 2023
Summary:
Pull Request resolved: facebook#1325

Fixes facebook#1321

Differential Revision: https://internalfb.com/D47368830

fbshipit-source-id: 2305060e225bed8e8246772334caa580c8b03f8b
NickGerleman added a commit that referenced this issue Jul 13, 2023
Summary:
Pull Request resolved: #1325

Fixes #1321

Reviewed By: cortinico

Differential Revision: D47368830

fbshipit-source-id: 570a45ad7fd182ef82e6edda4037ae2f6faa0c75
@NickGerleman
Copy link
Contributor

Fix has been published in yoga-layout@2.0.0-beta.2

@zjt123
Copy link

zjt123 commented Aug 18, 2023

@NickGerleman
how can i get yoga-layout in 2.0.0 version

Could not find com.facebook.yoga.android:yoga-layout:2.0.0-beta.1

Could not find com.facebook.yoga.android:yoga-layout:2.0.0-beta.2

@NickGerleman
Copy link
Contributor

@NickGerleman how can i get yoga-layout in 2.0.0 version

Could not find com.facebook.yoga.android:yoga-layout:2.0.0-beta.1

Could not find com.facebook.yoga.android:yoga-layout:2.0.0-beta.2

This issue is for the yoga-layout npm package. The above names are for the Maven Central package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants