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
- Use the
makeConfig
and transform a bundle.
const config = makeConfig({
bundles: {
index: {
entry: withPolyfills('./index'),
transform: ({ config }) => console.log(config.resolve.extensions),
}
}
});
- Run
yarn haul start --dev --eager=ios
- 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:
- Put
debugger;
statement in transform of amakeConfig
- Run:
node --inspect-brk ./node_modules/.bin/haul start --dev
- Go to:
chrome://inspect/
in chrome and open a debugger - Open the app so it requests a bundle
- 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.