Open takethefake opened 7 months ago
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 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.
This issue is most likely due to using a very old node version (like 12 mentioned above) or old bundlers that do not support exports
entrypoints in package.json. I recommend bumping both
Any guys are using old node version like 12, needed to modify package-lock.json
to use a specific version of @react-pdf/layout
or might be needed to npm shrinkwrap to keep child dependencies safe. package-lock.json
itself would be override by npm install
https://stackoverflow.com/questions/15806152/how-do-i-override-nested-npm-dependency-versions
While modifying @react-pdf/layout
version manually in lock files work, bare in mind it's a workaround and the lib will move forward and might break at some point your setup by using older sub-dependencies
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-layout
didn't fix the problem, it just gave the same error again.)
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 both src/generated/YGEnums.js
AND src/generated/YGEnums.ts
exist.
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.
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.js
ANDsrc/generated/YGEnums.ts
exist.Whatever tool you're using to bundle your code:
- Resolves the above dependency to .ts file
- …but fails to parse it.
To resolve this, we would need to look at specific tool configuration where the bug is likely to be found.
ERROR: failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1. any idea
I'm currently using an AWS cdk NodeJsFunction with Node 18 and no special props that leads to a failing
this.#lambda = new NodejsFunction(scope, `${props.lambda.name}Lambda`, {
entry: props.lambda.entry,
handler: "handler",
functionName: props.lambda.name,
runtime: Runtime.NODEJS_18_X,
timeout: Duration.seconds(29),
role: this.#lambdaExecutionRole,
memorySize: 768,
vpc: props.lambda.vpc,
vpcSubnets: props.lambda.vpc ? props.lambda.vpcSubnets : undefined,
securityGroups: props.lambda.securityGroups,
logRetention: props.lambda.logRetention,
bundling: {
sourceMap: true,
minify: true,
keepNames: true,
externalModules: ["aws-sdk", "aws-cdk*"],
},
environment: props.lambda.environment,
layers: props.lambda.layers,
});
tmk: this uses esbuild
under the hood
Module not found: Can't resolve 'yoga-layout'
any suggestion?
Instead of putting it in the overrides, try adding @react-pdf/layout in the dependencies part of your package.json
Also be sure to nuke you node_modules and package-lock after making those changes.
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?
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?
what's ur version node? I using version 14.17.3 and when using renderer v3.1.14 and layout v3.6.3 still Module not found: Can't resolve 'yoga-layout' in @react-pdf/layout/lib
Same problem. Node v20.9.0.
Hello, any update on this issue ?
Hello, any...
REPRODUCIBLE EXAMPLES? 🙏😁
Can't get it breaking on my setup!
any updates?
Hello, any...
REPRODUCIBLE EXAMPLES? 🙏😁
Can't get it breaking on my setup!
If I have later or tomorrow enough time, I will create an example and upload it on GitHub.
I have the same error on my project.
We are using Webpack and at some time in the build it tries to load YGEnums.ts
and fail.
If I rename this file, it works fine !!!
Not really a fix but it may help to understand the problem
Hello, any...
REPRODUCIBLE EXAMPLES? 🙏😁
Can't get it breaking on my setup!
You quick-start guide is reproducible example. After fresh project creation and adding react-pdf every project stop working
Hello, any...
REPRODUCIBLE EXAMPLES? 🙏😁
Can't get it breaking on my setup!
Wich examples are you need? It broken from 'Starting with react-pdf is extremely simple.' - line of your documentation
Before you guys updated it to the latest version I was using 3.3.4 and it was working fine, the only issue with that version was flickering of whole page when updating data using useState, now when I tried to reuse the same it showed error of module not found: yoga-layout. To reproduce this now you just need to install it with older version of node as I was using v14, it will show the error @wojtekmaj
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?
I am using rendered v3.1.14 and layout v3.6.4. Rendering is not working in this case too. Getting this error on console:
TypeError: a is not a function
at 349.js:2:35575
at 349.js:2:8769
at Array.map (
Has anyone got the solution for this?
@vivekdhiman007 Node.js is not officially supported, we can't support it even if we wanted to, as there are dependencies that already don't officially support Node.js 14 (yoga-layout is an ESM module, so I'd expect issues below Node.js 16 for sure).
If you can reproduce the error on Node.js 18 at minimum, we could look into this.
@shesha4kr This is an error from the bundled, minified version of your code. We can't tell what's crashing. You'll have to either reproduce the error on non-minified version of your code or ship source maps along with your code so that we could see what is actually the cause.
@wojtekmaj please check out my reproduce repo, I just setup with nx and react and it won't work. https://github.com/lyhourchhen/react-pdf-reproduce-bug, I belive this relate to webpack5 & i also tried with vite and it working fine.
Try adding
resolve: {
extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
}
to Webpack config.
@shesha4kr This is an error from the bundled, minified version of your code. We can't tell what's crashing. You'll have to either reproduce the error on non-minified version of your code or ship source maps along with your code so that we could see what is actually the cause.
@wojtekmaj Hi, please refer this screenshot:
@wojtekmaj , Hey, hi. i am using node version 18.18.2. and still receiving this error.
@shesha4kr This is completely unrelated to this thread. Please raise a separate issue.
Hello, any... REPRODUCIBLE EXAMPLES? 🙏😁 Can't get it breaking on my setup!
- Create a new react project using latest using latest Node.js and react-scripts
- Type 'npm install @react-pdf/renderer --save'
- Booom! Project failed to start with 'Module not found: Can't resolve 'yoga-layout'
Wich examples are you need? It broken from 'Starting with react-pdf is extremely simple.' - line of your documentation
Started a new project using CRA and following your instructions, and it worked just fine:
That's why reproducible examples, like broken repo, broken CodeSandbox or something, are needed if you want help.
Hello, any... REPRODUCIBLE EXAMPLES? 🙏😁 Can't get it breaking on my setup!
- Create a new react project using latest using latest Node.js and react-scripts
- Type 'npm install @react-pdf/renderer --save'
- Booom! Project failed to start with 'Module not found: Can't resolve 'yoga-layout'
Wich examples are you need? It broken from 'Starting with react-pdf is extremely simple.' - line of your documentation
Started a new project using CRA and following your instructions, and it worked just fine:
That's why reproducible examples, like broken repo, broken CodeSandbox or something, are needed if you want help.
Hi, please refer this repo where the issue can be replicated: https://github.com/shesha4kr/react-pdf-example
@shesha4kr This is completely unrelated to this thread. Please raise a separate issue.
The repo which I shared will work fine if you add "@react-pdf/layout": "3.6.4" in dependency list. But PDF rendering will stop working with same error in console which I mentioned earlier
@shesha4kr thank you so much. It all comes down to this line in your Webpack config:
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js", ".json"],
},
You specifically configured Webpack to prefer .ts
files over .js
files, everywhere, INCLUDING in node_modules
, and yet you specifically excluded parsing .ts
files in node_modules
(which is the right thing to do):
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
use: { loader: "babel-loader" },
},
Change it like this:
resolve: {
- extensions: [".tsx", ".ts", ".jsx", ".js", ".json"],
+ extensions: [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"],
},
as suggested earlier and it works like a charm!
I fixed the Error on my side by adjusting my build configuration. I am using cdk which has set a default for --prefer-ts-exts
in the ts-node call (see https://github.com/aws/aws-cdk/pull/11470). In my case removing this worked, but could not be done in every cdk project.
Nevertheless, yoga-layout should not include the ts-files in the build, or am I wrong?
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
Can you provide more details
re-installing the latest version of react-pdf helped to get rid of that issue for me.
npm i react-pdf
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 |
---|
export enum Align { | Auto = 0, | FlexStart = 1, @ ./node_modules/yoga-layout/src/entrypoint/wasm-async-web.js 11:15-46 @ ./node_modules/@react-pdf/layout/lib/index.cjs 13:11-33 @ ./node_modules/@react-pdf/renderer/lib/react-pdf.browser.cjs 14:21-49 @ ./src/pages/LoginPage.tsx 164:17-47
webpack 5.90.3 compiled with 1 error in 5575 ms
Had this issue
2209 | return node;
2210 | };
2211 | };
2212 |
2213 | var OVERFLOW = {
2214 | hidden: Yoga__namespace.Overflow.Hidden,
^
TypeError: undefined is not an object (evaluating 'Yoga__namespace.Overflow.Hidden')
at /node_modules/.pnpm/@react-pdf+layout@3.11.2/node_modules/@react-pdf/layout/lib/index.cjs:2214:10
at globalThis (/node_modules/.pnpm/@react-pdf+layout@3.11.2/node_modules/@react-pdf/layout/lib/index.cjs:3876:18)
at overridableRequire (:1:20)
at /node_modules/.pnpm/react-pdf-html@1.2.0_@react-pdf+renderer@3.1.14_react@18.2.0/node_modules/react-pdf-html/node_modules/@react-pdf/renderer/lib/react-pdf.cjs.js:14:4
at globalThis (/node_modules/.pnpm/react-pdf-html@1.2.0_@react-pdf+renderer@3.1.14_react@18.2.0/node_modules/react-pdf-html/node_modules/@react-pdf/renderer/lib/react-pdf.cjs.js:4420:1)
at overridableRequire (:1:20)
at /node_modules/.pnpm/react-pdf-html@1.2.0_@react-pdf+renderer@3.1.14_react@18.2.0/node_modules/react-pdf-html/dist/renderers.js:8:6
at globalThis (/node_modules/.pnpm/react-pdf-html@1.2.0_@react-pdf+renderer@3.1.14_react@18.2.0/node_modules/react-pdf-html/dist/renderers.js:122:18)
this is what I had in package.json
"@react-pdf/renderer": "3.3.8",
tried every solution suggested above, didn't work
updated bun, - worked
bun -v
1.0.12
curl -fsSL https://bun.sh/install | bash
######################################################################## 100.0%
bun was installed successfully to ~/.bun/bin/bun
Run 'bun --help' to get started
bun -v
1.0.29
This issue is most likely due to using a very old node version (like 12 mentioned above) or old bundlers that do not support
exports
entrypoints in package.json. I recommend bumping both
my node version is 20.1.0 and still having this issue
@shesha4kr This is an error from the bundled, minified version of your code. We can't tell what's crashing. You'll have to either reproduce the error on non-minified version of your code or ship source maps along with your code so that we could see what is actually the cause.
@wojtekmaj Hi, please refer this screenshot:
@shesha4kr In the same exact boat as you, were you able to find a solution?
I think it's more a Webpack issue
A simple workaround
{
"scripts": {
"postinstall": "npm run fix:react-pdf",
"fix:react-pdf": "mv ./node_modules/yoga-layout/src/generated/YGEnums.ts ./node_modules/yoga-layout/src/generated/YGEnums_bkp.ts || echo \"not found or already processed\""
}
}
@shesha4kr I got this error too. Did you resolve this?
@shesha4kr This is an error from the bundled, minified version of your code. We can't tell what's crashing. You'll have to either reproduce the error on non-minified version of your code or ship source maps along with your code so that we could see what is actually the cause.
@wojtekmaj Hi, please refer this screenshot:
@shesha4kr In the same exact boat as you, were you able to find a solution?
Mine was webpack issue. I did the changes in webpack.config.js as suggested
@shesha4kr I got this error too. Did you resolve this?
Mine was webpack issue.
@shesha4kr could you share your webpack config?
Hello, any... REPRODUCIBLE EXAMPLES? 🙏😁 Can't get it breaking on my setup!
- Create a new react project using latest using latest Node.js and react-scripts
- Type 'npm install @react-pdf/renderer --save'
- Booom! Project failed to start with 'Module not found: Can't resolve 'yoga-layout'
Wich examples are you need? It broken from 'Starting with react-pdf is extremely simple.' - line of your documentation
Started a new project using CRA and following your instructions, and it worked just fine:
That's why reproducible examples, like broken repo, broken CodeSandbox or something, are needed if you want help.
Hi, please refer this repo where the issue can be replicated: https://github.com/shesha4kr/react-pdf-example
@ryanpratama14 refer this repo.
@shesha4kr thank you so much. It all comes down to this line in your Webpack config:
resolve: { extensions: [".tsx", ".ts", ".jsx", ".js", ".json"], },
You specifically configured Webpack to prefer
.ts
files over.js
files, everywhere, INCLUDING innode_modules
, and yet you specifically excluded parsing.ts
files innode_modules
(which is the right thing to do):{ test: /\.(ts|tsx|js|jsx)$/, exclude: /node_modules/, use: { loader: "babel-loader" }, },
Change it like this:
resolve: { - extensions: [".tsx", ".ts", ".jsx", ".js", ".json"], + extensions: [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"], },
as suggested earlier and it works like a charm!
@ryanpratama14 and this was the fix
@shesha4kr many thanks!
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)\/).*/ } ..... ]
Describe the bug I migrated today from
3.1.14
to3.1.17
and received the following error while deploying.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.