callstack / repack

A Webpack-based toolkit to build your React Native application with full support of Webpack ecosystem.
https://re-pack.dev
MIT License
1.44k stars 104 forks source link

Error : TypeError: Cannot read properties of undefined (reading 'forEach') #644

Closed jhso-dev closed 1 month ago

jhso-dev commented 3 months ago

Is it possible for chunk to be passed into Platform? I encountered the following error and upon investigation, I found that chunk is being passed into Platform.

ℹ [00:44:56.585Z][WebpackCompilerWorker] env {
  bundleFilename: '',
  context: '/Users/x/dev/client/packages/app',
  reactNativePath: '/Users/x/dev/client/node_modules/react-native',
  mode: 'development',
  platform: 'chunk',
  devServer: { port: 8081, host: '', https: undefined, hmr: true }
}
✖ [00:44:56.603Z][DevServer] Failed to create code frame {
  reqId: 'req-e',
  error: "ENOENT: no such file or directory, open '/Users/x/dev/client/packages/app/node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js'"
}
ℹ [00:44:56.604Z][DevServer] POST 200 /symbolicate request completed { responseTime: 12.083624988794327 }
platform chunk undefined
node:internal/event_target:1062
  process.nextTick(() => { throw err; });
                           ^

TypeError: Cannot read properties of undefined (reading 'forEach')
    at Worker.<anonymous> (/Users/x/dev/client/node_modules/@callstack/repack/dist/webpack/Compiler.js:107:36)
    at Worker.emit (node:events:517:28)
    at MessagePort.<anonymous> (node:internal/worker:256:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:786:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

Node.js v18.20.2
jbroma commented 3 months ago

Hi @jhso-dev, what version of Re.Pack is this from?

jhso-dev commented 3 months ago

@jbroma Hi jbroma, I am using repack 3.7.0 and react-native 0.73.7. I also tried it with 4.1.1 Thanks in advance!

jbroma commented 3 months ago

Can you share a reproduction repository please? I'm not able to pinpoint anything from the trace you've provided. No clue how 'chunk' could end up as a platform 🤔.

I also can't locate the error from this trace, I've check 3.7.0 and 4.1.1 and none of them match this:

TypeError: Cannot read properties of undefined (reading 'forEach')
    at Worker.<anonymous> (/Users/x/dev/client/node_modules/@callstack/repack/dist/webpack/Compiler.js:107:36)
    at Worker.emit (node:events:517:28)
    at MessagePort.<anonymous> (node:internal/worker:256:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:786:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

EDIT: The only thing that comes to mind is customizing platform through CLI args, can you verify that you are not passing --platform=chunk anywhere in your config by mistake?

jhso-dev commented 3 months ago

@jbroma Hi jbroma :)

I did some research and found that the platform(chunk) is parsed from the URL from getSourceMap http://localhost:8081/ios/src_app2_tsx-node_modules_react-native-reanimated_src_reanimated2_sync_recursive.chunk.bundle

Please refer to the source below: https://github.com/callstack/repack/blob/c0f9b7eaddffed993f488594d9ffd507214f9df9/packages/repack/src/commands/start.ts#L263

So, if I manually change the platform from parseFileUrl to either ios or android, it seems to work correctly.

jbroma commented 3 months ago

Oh, now with the added context it makes way more sense! Great find, that's definitely a bug that needs to be fixed, would you like to open a PR with a fix for that?

jhso-dev commented 2 months ago

@jbroma please review the pull request when you have a moment? Thank you! https://github.com/callstack/repack/pull/647

github-actions[bot] commented 1 month ago

This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.

github-actions[bot] commented 1 month ago

This issue has been automatically closed because it has been inactive for more than 14 days. Please reopen if you want to add more context.

jbroma commented 1 month ago

Fixed by #647