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

Add missing @stylexjs/babel-plugin in web-example #6886

Merged
merged 4 commits into from
Jan 10, 2025

Conversation

tomekzaw
Copy link
Member

@tomekzaw tomekzaw commented Jan 10, 2025

Summary

This PR fixes the following errors that occur when trying to run web-example using yarn start --reset-cache:

Web Bundling failed 174ms apps/web-example/index.js (1 module)
 ERROR  index.js: Cannot find module '@stylexjs/babel-plugin'
Require stack:
- /Users/tomekzaw/RNOS/react-native-reanimated/apps/web-example/babel.config.js
- /Users/tomekzaw/RNOS/react-native-reanimated/node_modules/@babel/core/lib/config/files/module-types.js
- /Users/tomekzaw/RNOS/react-native-reanimated/node_modules/@babel/core/lib/config/files/configuration.js
- /Users/tomekzaw/RNOS/react-native-reanimated/node_modules/@babel/core/lib/config/files/index.js
- /Users/tomekzaw/RNOS/react-native-reanimated/node_modules/@babel/core/lib/index.js
- /Users/tomekzaw/RNOS/react-native-reanimated/apps/web-example/node_modules/@expo/metro-config/build/transform-worker/metro-transform-worker.js
- /Users/tomekzaw/RNOS/react-native-reanimated/apps/web-example/node_modules/@expo/metro-config/build/transform-worker/transform-worker.js
- /Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/DeltaBundler/Worker.flow.js
- /Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/DeltaBundler/Worker.js
- /Users/tomekzaw/RNOS/react-native-reanimated/node_modules/jest-worker/build/workers/processChild.js

Then I faced another error:

Web Bundling failed 5562ms apps/web-example/index.js (1325 modules)
 ERROR  ReferenceError: SHA-1 for file /Users/tomekzaw/RNOS/react-native-reanimated/node_modules/@react-native/js-polyfills/error-guard.js is not computed.
         Potential causes:
           1) You have symlinks in your project - watchman does not follow symlinks.
           2) Check `blockList` in your metro.config.js and make sure it isn't excluding the file path.
    at DependencyGraph.getSha1 (/Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/node-haste/DependencyGraph.js:181:13)
    at Transformer._getSha1 (/Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/Bundler.js:15:26)
    at Transformer.transformFile (/Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/DeltaBundler/Transformer.js:92:19)
    at Bundler.transformFile (/Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/Bundler.js:43:30)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Object.transform (/Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/lib/transformHelpers.js:134:12)
    at transform (/Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/DeltaBundler/Graph.js:164:26)
    at visit (/Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/DeltaBundler/buildSubgraph.js:82:29)
    at async Promise.all (index 3)
    at buildSubgraph (/Users/tomekzaw/RNOS/react-native-reanimated/node_modules/metro/src/DeltaBundler/buildSubgraph.js:103:3)

Turns out it's dependent on whether react-native is hoisted or not so I applied the following patch for metro.config.js that @tjzel had sent me:

const hasReactNative = require.resolve('react-native/package.json', {
  paths: [projectRoot],
});
if (!hasReactNative) {
  const modulesToBlock = ['@react-native'];
  // @ts-expect-error
  config.resolver.blacklistRE = exclusionList(
    modulesToBlock.map(
      (m) =>
        new RegExp(
          `^${escape(path.join(monorepoRoot, 'node_modules', m))}\\/.*$`
        )
    )
  );
}

Finally, I bumped react-native-web and @expo/metro-runtime to the latest versions.

Now we can launch web-example using yarn start --reset-cache.

Test plan

@tomekzaw tomekzaw marked this pull request as ready for review January 10, 2025 14:46
@tomekzaw tomekzaw added this pull request to the merge queue Jan 10, 2025
Merged via the queue into main with commit f4319a0 Jan 10, 2025
9 checks passed
@tomekzaw tomekzaw deleted the @tomekzaw/fix-web-example-missing-stylex-babel-plugin branch January 10, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants