callstack / haul

Haul is a command line tool for developing React Native apps, powered by Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid Extensions due to missing platform

meznaric opened this issue · comments

Environment

Haul Version: 0.15.0
Node: v10.17.0
React Native: 0.61.4

Description

Seems like wrong extension list gets generated in development mode and then resolutions fail. It's missing platform specific versions.

[ '..js',
  '..jsx',
  '.native.js',
  '.native.jsx',
  '.js',
  '.jsx',
  '..ts',
  '..tsx',
  '.native.ts',
  '.native.tsx',
  '.ts',
  '.tsx' ]

I believe this line is the cause of the issue:

Reproducible Demo

  1. Use the makeConfig and transform a bundle.
const config = makeConfig({
  bundles: {
    index: {
      entry: withPolyfills('./index'),
      transform: ({ config }) => console.log(config.resolve.extensions),
    }
  }
});
  1. Run yarn haul start --dev --eager=ios
  2. You should see the wrong list of extensions

platform: '', in start command is on purpose, since start command needs some info from config, but the actual config specific for the platform is generated elsewhere - in compiler worker. Each worker is specific to the platform and each worker generated their config with proper platform so for example for ios compiler worker, the config for webpack will look like this:

[ '.ios.js',
  '.ios.jsx',
  '.native.js',
  '.native.jsx',
  '.js',
  '.jsx',
  '.ios.ts',
  '.ios.tsx',
  '.native.ts',
  '.native.tsx',
  '.ts',
  '.tsx' ]

So in other words, haul.config.js will be evaluated multiple times. The logs you have are form the first evaluation and webpack config from this first evaluation will not be used.

@zamotany I put a debugger; statement in transform, hoping to capture when it evaluates the second time. It doesn't happen. Not if I use --eager=ios or if simulator requests a bundle.

transform({ config, env }) => console.log(env.platform) will also only print empty string.

How I used debugger:

  1. Put debugger; statement in transform of a makeConfig
  2. Run: node --inspect-brk ./node_modules/.bin/haul start --dev
  3. Go to: chrome://inspect/ in chrome and open a debugger
  4. Open the app so it requests a bundle
  5. It stops in transform only once, the first time, without the platfrom

You put debugger in main process, workers are a separate processes, that's why you don't get breakpoint hit the 2nd time. You would need to spawn workers with --inspect-brk here:
https://github.com/callstack/haul/blob/master/packages/haul-core-legacy/src/compiler/createForkProcess.js#L34
and then add debugger somewhere here:
https://github.com/callstack/haul/tree/master/packages/haul-core-legacy/src/compiler/worker

@zamotany thanks for insane response time. You are right. platform is passed in a worker.