question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

runBeforeMainModule is an empty array

See original GitHub issue

Do you want to request a feature or report a bug? report a bug

What is the current behavior? runBeforeMainModule is an empty array. I noticed that runBeforeMainModule config was removed from metro-bundler in this commit Make the runBeforeMainModule config param to RN repo and make it absolute. runBeforeMainModule is passed into Server instance in react-native local-cli.

const options = {
      assetExts: defaultAssetExts.concat(assetExts),
      assetRegistryPath: ASSET_REGISTRY_PATH,
      blacklistRE: config.getBlacklistRE(),
      extraNodeModules: config.extraNodeModules,
      getPolyfills: config.getPolyfills,
      getTransformOptions: config.getTransformOptions,
      globalTransformCache: null,
      hasteImpl: config.hasteImpl,
      maxWorkers: args.maxWorkers,
      platforms: defaultPlatforms.concat(platforms),
      postMinifyProcess: config.postMinifyProcess,
      postProcessModules: config.postProcessModules,
      postProcessBundleSourcemap: config.postProcessBundleSourcemap,
      projectRoots: config.getProjectRoots(),
      providesModuleNodeModules: providesModuleNodeModules,
      resetCache: args.resetCache,
      reporter: new TerminalReporter(terminal),
      runBeforeMainModule: config.runBeforeMainModule,
      sourceExts: defaultSourceExts.concat(sourceExts),
      transformCache: TransformCaching.useTempDir(),
      transformModulePath: transformModulePath,
      useDeltaBundler: false,
      watch: false,
      workerPath: config.getWorkerPath && config.getWorkerPath(),
};

packagerInstance = new Server(options);

However, runBeforeMainModule is not passed into bundle options. In shared/output/bundle.js module, runBeforeMainModule is not included when packagerClient.buildBundle is called.

// shared/output/bundle.js
function buildBundle(packagerClient: Server, requestOptions: RequestOptions) {
  return packagerClient.buildBundle({
    ...Server.DEFAULT_BUNDLE_OPTIONS,
    ...requestOptions,
    isolateModuleIDs: true,
  });
}

In Server/index module, runBeforeMainModule is also not included when this._bundler.bundle(options) is called.

async buildBundle(options: BundleOptions): Promise<Bundle> {
    const bundle = await this._bundler.bundle(options);
    const modules = bundle.getModules();
    const nonVirtual = modules.filter(m => !m.virtual);
    bundleDeps.set(bundle, {
      files: new Map(
        nonVirtual.map(({sourcePath, meta}) => [
          sourcePath,
          meta != null ? meta.dependencies : [],
        ]),
      ),
      idToIndex: new Map(modules.map(({id}, i) => [id, i])),
      dependencyPairs: new Map(
        nonVirtual
          .filter(({meta}) => meta && meta.dependencyPairs)
          .map(m => [m.sourcePath, m.meta.dependencyPairs]),
      ),
      outdated: new Set(),
    });
    return bundle;
  }

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior? Shouldn’t this._opts.runBeforeMainModule merged into options when this._bundler.bundle(options) is called in buildBundle function of Server module?

Please provide your exact metro-bundler configuration and mention your metro-bundler, node, yarn/npm version and operating system.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
miguelocarvajalcommented, Nov 8, 2017

That was the case. That resolved it! Thanks so much!

0reactions
rafecacommented, Nov 8, 2017

oh, just realized that if you’re using import syntax, you’ll need to also import InitializeCore (import Foo from 'InitializeCore';), since imports are hoisted before the require statements. Is this the case?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Check if a JavaScript Array is Empty or Not with .length
To check if an array is empty or not, you can use the .length property. The length property sets or returns the number...
Read more >
How do I empty an array in JavaScript? - Stack Overflow
Ways to clear an existing array A : Method 1. (this was my original answer to the question) A = [];. This code...
Read more >
5 ways to check if a Javascript Array is empty - Level Up Coding
I'll shortly describe what Javascript (JS) array is, how we use it and then I'll describe how we can check whether it's empty....
Read more >
How to handle empty arrays - Power Platform Community
I have 4 columns to fill, Name, OS, IP and Date. The data for Name, OS and IP are in arrays, but they...
Read more >
Determine whether array is empty - MATLAB isempty
Compare empty arrays to arrays containing missing values. In MATLAB®, an empty array has at least one dimension length equal to zero. An...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found