Haul: Cannot find module error in workspaces setting

Created on 19 Jul 2018  路  2Comments  路  Source: callstack/haul

I upgraded Haul from 1.0.0-beta.14 to 1.0.0-RC.5 and get an error since then. If I revert back to beta version and the error is gone.

Current Behavior

Wether it's with iOS or Android, debug or release, I get this error:
Cannot find module '{projectRoot}/packages/mobile/node_modules/react-native/Libraries/Core/InitializeCore.js'

Expected Behavior

Haul should create a JS bundle
Haul should search for modules inside {projectRoot}/node_modules and not inside the package's node_modules folder which doesn't contain anything.

Haul Configuration (webpack.haul.js)

import { createWebpackConfig } from 'haul';

export default {
  webpack: env => {
    const config = createWebpackConfig({
      entry: `./src/index.tsx`,
      include: '../../node_modules'
    })(env);

    config.module.rules = [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader'
      },
      ...config.module.rules
    ];

    config.resolve.extensions = [
      '.ts',
      '.tsx',
      `.${env.platform}.ts`,
      '.native.ts',
      `.${env.platform}.tsx`,
      '.native.tsx',
      ...config.resolve.extensions
    ];

    return config;
  }
};

Your Environment

| software | version
| ---------------- | -------
| Haul | 1.0.0-RC.5
| react-native | ~0.55.2
| node | v9.11.2
| npm or yarn | yarn 1.7.0

I'm using mono repo using workspaces in yarn with lerna. All my modules are installed in {projectRoot}/node_modules.

Most helpful comment

I am not sure if this is correct, but I had basically the same issue and I fixed it like this:

    webpack: env => {
        // account for hoisted 'Core' location
        env.initializeCoreLocation = '../../node_modules/react-native/Libraries/Core/InitializeCore.js';

        const config = createWebpackConfig({
            entry: `./index.${env.platform}.js`,
        })(env);

I did not find this in docs (perhaps it is documented somewhere?), I went digging into the code and found it in here:
https://github.com/callstack/haul/blob/next/src/utils/makeReactNativeConfig.js

Like I said, I'm not sure if this should be necessary, but it was a way that I got it to work.

All 2 comments

I am not sure if this is correct, but I had basically the same issue and I fixed it like this:

    webpack: env => {
        // account for hoisted 'Core' location
        env.initializeCoreLocation = '../../node_modules/react-native/Libraries/Core/InitializeCore.js';

        const config = createWebpackConfig({
            entry: `./index.${env.platform}.js`,
        })(env);

I did not find this in docs (perhaps it is documented somewhere?), I went digging into the code and found it in here:
https://github.com/callstack/haul/blob/next/src/utils/makeReactNativeConfig.js

Like I said, I'm not sure if this should be necessary, but it was a way that I got it to work.

This seems like what I was searching for, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Traviskn picture Traviskn  路  4Comments

satya164 picture satya164  路  7Comments

Natteke picture Natteke  路  6Comments

rdy picture rdy  路  3Comments

aaronkchsu picture aaronkchsu  路  5Comments