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

Webpack: Fix export 'act' (imported as 'React4') was not found in 'react' errors in webpack #29235

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

kasperpeulen
Copy link
Contributor

@kasperpeulen kasperpeulen commented Sep 27, 2024

What I did

In wepback the following error is thrown when act doesn't exist in React:
export 'act' (imported as 'React4') was not found in 'react' errors in webpack

We do check if act exists, but webpack will still throw an error on compile time

Cloning the react module avoid this problem.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 77.6 MB 77.6 MB 76 B 0.6 0%
initSize 143 MB 143 MB 179 B -1.98 0%
diffSize 65.1 MB 65.1 MB 103 B -1.99 0%
buildSize 6.87 MB 6.87 MB 0 B -0.29 0%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B -0.62 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.9 MB 1.9 MB 0 B 2.38 0%
buildSbPreviewSize 271 kB 271 kB 0 B -0.42 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.88 MB 3.88 MB 0 B -0.29 0%
buildPreviewSize 3 MB 3 MB 0 B -0.65 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 20.7s 17.5s -3s -196ms 0.66 -18.2%
generateTime 24.4s 23.3s -1s -103ms 0.65 -4.7%
initTime 16.6s 17.1s 548ms 1.71 3.2%
buildTime 7.8s 10.3s 2.4s 0.74 23.8%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.7s 6.5s 793ms -0.52 12.1%
devManagerResponsive 3.5s 3.8s 340ms -1.09 8.7%
devManagerHeaderVisible 543ms 628ms 85ms -0.25 13.5%
devManagerIndexVisible 622ms 698ms 76ms -0.21 10.9%
devStoryVisibleUncached 1.1s 1.1s 20ms -0.17 1.7%
devStoryVisible 620ms 697ms 77ms -0.09 11%
devAutodocsVisible 486ms 594ms 108ms -0.15 18.2%
devMDXVisible 403ms 522ms 119ms -0.69 22.8%
buildManagerHeaderVisible 526ms 568ms 42ms -0.76 7.4%
buildManagerIndexVisible 542ms 578ms 36ms -0.81 6.2%
buildStoryVisible 518ms 567ms 49ms -0.74 8.6%
buildAutodocsVisible 447ms 481ms 34ms -0.83 7.1%
buildMDXVisible 434ms 482ms 48ms -0.59 10%

@kasperpeulen kasperpeulen changed the title Fix export 'act' (imported as 'React4') was not found in 'react' errors in webpack Webpack: Fix export 'act' (imported as 'React4') was not found in 'react' errors in webpack Sep 27, 2024
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

// We need to spread React to avoid
// export 'act' (imported as 'React4') was not found in 'react' errors in webpack
// We do check if act exists, but webpack will still throw an error on compile time
const clonedReact = { ...React };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Cloning React object may increase bundle size

Copy link

nx-cloud bot commented Sep 27, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit e15a431. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@kasperpeulen kasperpeulen self-assigned this Sep 30, 2024
@kasperpeulen kasperpeulen merged commit 894e809 into next Oct 29, 2024
59 checks passed
@kasperpeulen kasperpeulen deleted the kasper/act-fix branch October 29, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants