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

fix(react): assert test property is defined on webpack rule in nx-react-webpack-plugin #27525

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

nigelwtf
Copy link
Contributor

The removeSvgLoaderIfPresent method in apply-react-config.ts iterates through each Webpack rule, calls toString on each test property, and checks for the presence of the string "svg" to see if any existing SVG plugins need to be removed.

Some of the Webpack rules in the config don't have the test property, and calling toString without asserting the test property is defined first throws type errors.

This commit introduces a very small change that simply asserts that rule.test is not undefined before calling .toString().

Current Behavior

Running a React Webpack library with svgr enabled causes compilation errors.

Screenshot 2024-08-20 at 10 36 09 AM Screenshot 2024-08-20 at 10 39 28 AM

Expected Behavior

Enabling SVGR in the NxReactWebpackPlugin config should compile as normal.

Related Issue(s)

N/A

@nigelwtf nigelwtf requested a review from a team as a code owner August 19, 2024 23:12
@nigelwtf nigelwtf requested a review from ndcunningham August 19, 2024 23:12
Copy link

vercel bot commented Aug 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 10:10am

@nigelwtf
Copy link
Contributor Author

Hey @ndcunningham - hope you're doing well.

Not sure how big your backlog is atm—just wondering if you'd had a chance to peek at this yet?

@FrozenPandaz FrozenPandaz changed the title fix(nx-plugin): assert test property is defined on webpack rule in nx-react-webpack-plugin fix(react): assert test property is defined on webpack rule in nx-react-webpack-plugin Nov 15, 2024
nigelwtf and others added 2 commits December 11, 2024 10:05
…-react-webpack-plugin

The `removeSvgLoaderIfPresent` method in `apply-react-config.ts` iterates through each Webpack rule,
calls `toString` on each `test` property, and checks for the presence of the string `"svg"` to see
if any existing SVG plugins need to be removed.

Some of the Webpack rules in the config don't have the test property, and calling `toString` without
asserting the test property is defined first throws type errors.

This commit introduces a very small change that simply asserts that `rule.test` is not `undefined`
before calling `.toString()`.
@Coly010 Coly010 requested a review from a team as a code owner December 11, 2024 10:08
@Coly010 Coly010 enabled auto-merge (squash) December 11, 2024 10:09
@Coly010 Coly010 merged commit e4939fa into nrwl:master Dec 11, 2024
5 checks passed
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants