react-pdf: Yoga-layout v2 leads to failing builds
Describe the bug
I migrated today from 3.1.14 to 3.1.17 and received the following error while deploying.
+ yarn run deploy
/azp/_work/1/s/node_modules/yoga-layout/src/generated/YGEnums.ts:10
export enum Align {
^^^^^^
SyntaxError: Unexpected token 'export'
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1274:20)
at Module._compile (node:internal/modules/cjs/loader:1320:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
at Object.require.extensions.<computed> [as .ts] (/azp/_work/1/s/node_modules/ts-node/src/index.ts:1608:43)
at Module.load (node:internal/modules/cjs/loader:1197:32)
at Function.Module._load (node:internal/modules/cjs/loader:1013:12)
at Module.require (node:internal/modules/cjs/loader:1225:19)
at require (node:internal/modules/helpers:177:18)
at Object.<anonymous> (/azp/_work/1/s/node_modules/yoga-layout/src/wrapAssembly.js:10:1)
this seems to be related to the migration to yoga-layout@2.01. I for now downgraded to @react-pdf/layout:3.6.4 via resolutions.
About this issue
- Original URL
- State: open
- Created 5 months ago
- Reactions: 10
- Comments: 50 (10 by maintainers)
Commits related to this issue
- fixed the issue with @react-pdf library more info here: https://github.com/diegomura/react-pdf/issues/2499 — committed to PreetiW/ros-frontend by PreetiW 3 months ago
- RHINENG-8218 dependencies upgrade: react 18, patternfly V5 and more (#322) * RHINENG-8218 dependencies upgrade: react 18, patternfly V5 and more * @redhat-cloud-services/frontend-components-config... — committed to RedHatInsights/ros-frontend by PreetiW 3 months ago
- RHINENG-8218 dependencies upgrade: react 18, patternfly V5 and more (#322) * RHINENG-8218 dependencies upgrade: react 18, patternfly V5 and more * @redhat-cloud-services/frontend-components-config ... — committed to RedHatInsights/ros-frontend-build by invalid-email-address 3 months ago
- RHINENG-8218 dependencies upgrade: react 18, patternfly V5 and more (#322) * RHINENG-8218 dependencies upgrade: react 18, patternfly V5 and more * @redhat-cloud-services/frontend-components-config ... — committed to RedHatInsights/ros-frontend-build by invalid-email-address 3 months ago
I think it’s more a Webpack issue
A simple workaround
@shesha4kr thank you so much. It all comes down to this line in your Webpack config:
You specifically configured Webpack to prefer
.tsfiles over.jsfiles, everywhere, INCLUDING innode_modules, and yet you specifically excluded parsing.tsfiles innode_modules(which is the right thing to do):Change it like this:
as suggested earlier and it works like a charm!
Try adding
to Webpack config.
Same problem. Node v20.9.0.
I have also got this issue 279.4 ERROR in ./node_modules/yoga-layout/src/generated/YGEnums.ts 10:7 279.4 Module parse failed: Unexpected token (10:7) 279.4 You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders 279.4 | // @generated by enums.py 279.4 | 279.4 > export enum Align { 279.4 | Auto = 0, 279.4 | FlexStart = 1, 279.4 @ ./node_modules/yoga-layout/src/entrypoint/asmjs-sync-web.js 9:15-46 279.4 @ ./node_modules/@react-pdf/layout/lib/index.js 13:0-42 1532:11-34 1532:37-55 1532:58-68 279.4 @ ./node_modules/@react-pdf/renderer/lib/react-pdf.browser.js 11:0-47 4194:19-33 279.4 @ ./src/pages/webReporting/pages/WebReporting/WebReporting.tsx 279.4 @ ./src/pages/webReporting/WebReportingLayout.tsx 1:0-61 4:27-39 279.4 @ ./src/pages/App.tsx 279.4 @ ./src/App.tsx 7:0-40 123:129-138 125:31-40 279.4 @ ./src/index.tsx 10:0-24 30:32-35 54:32-35 279.4 279.4 webpack 5.75.0 compiled with 1 error in 268339 ms
Dockerfile:14
12 | COPY . . 13 |
14 | >>> RUN npm run build 15 |
16 | # nginx state for serving content
ERROR: failed to solve: process “/bin/sh -c npm run build” did not complete successfully: exit code: 1. any idea
Getting this after installing react-pdf/renderer:
ERROR in ./node_modules/yoga-layout/src/generated/YGEnums.ts 10:7 Module parse failed: Unexpected token (10:7) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders | // @generated by enums.py |
webpack 5.90.3 compiled with 1 error in 5575 ms
Module not found: Can’t resolve ‘yoga-layout’
any suggestion?
I am also experiencing similar issue in Jest when running my unit test on node 14.12.0.
Cannot find module 'yoga-layout/sync' from 'node_modules/@react-pdf/layout/lib/index.cjs.js'I agree with OP Upgraded yoga to v2 and removed bundled package seems to be the issue.
Adding overrides to @react-pdf/layout:3.6.4 (version before removing @react-pdf/yoga) to package.json temporarily resolves issue.
Screenshot
my node version is 20.1.0 and still having this issue
when using renderer v3.1.14 and layout v3.6.3 it works but, the iframe it generates is left blank, therefore rendering is still not working with old versions. has anyone found fix for this issue?
This has to do with module resolution in yoga-layout. In
src/entrypoint/asmjs-async-web.js, they do:var _YGEnums = require("../generated/YGEnums");. Now the interesting bit is that bothsrc/generated/YGEnums.jsANDsrc/generated/YGEnums.tsexist.Whatever tool you’re using to bundle your code:
To resolve this, we would need to look at specific tool configuration where the bug is likely to be found.
I had the problem below when starting the project after installed react-pdf. The problem was caused by the newest version 3.1.17. After I changed the version to the 3.1.14 it started working. The problem was that the package.json had “@react-pdf/renderer”: “^3.1.14” which automatically installed the newest version 3.1.17. After I removed the
"^"it installed the correct old version.(The command
meteor npm install --save yoga-layoutdidn’t fix the problem, it just gave the same error again.)Describe the bug Hello, I’m experiencing an issue when installing “@react-pdf/renderer”: “3.1.17” and “@react-pdf/layout”: “3.6.4”. It’s showing the error “Module not found: Can’t resolve ‘yoga-layout/sync’.” I’m using Node version 12. help!!!
i’m using webpack and in my wepack config i’m using with rules for ts file and exclude node_modules except yoga-layout and moduleX as below. It’s worked for me and I forgot where I found the solution =)) rules: [ { test: /.tsx?$/, use: ‘ts-loader’, exclude: /node_modules/(?!(yoga-layout|moduleX)/).*/ } … ]
@shesha4kr In the same exact boat as you, were you able to find a solution?
Hi, please refer this repo where the issue can be replicated: https://github.com/shesha4kr/react-pdf-example
@wojtekmaj , Hey, hi. i am using node version 18.18.2. and still receiving this error.
@wojtekmaj Hi, please refer this screenshot:
You quick-start guide is reproducible example. After fresh project creation and adding react-pdf every project stop working
any updates?
Hello, any…
REPRODUCIBLE EXAMPLES? 🙏😁
Can’t get it breaking on my setup!
Hello, any update on this issue ?