1

Let's say I have a module A that is imported by module B in a webpack project.

A.js

const variable = synchronousGetData()

export function exportedFunction() {
  // do some work with variable
}

B.js

import { exportedFunction } from 'A'

exportedFunction()

Is variable guaranteed to be fully instantiated (e.g. the synchronous work will have been done and assigned to variable via synchronousGetData()?)

I can only think of the case where module A requires B as well, in which case you have a circular dependency, and this could throw things off, correct? But if no circular dependency is present then does the above guarantee exist?

Adam Thompson
  • 3,278
  • 3
  • 22
  • 37
  • 1
    The spec dictates that a module is completely evaluated before its exports are made available to another module. If webpack wouldn't do that for whatever reason, it's a bug. – Felix Kling Nov 16 '18 at 23:31
  • @FelixKling thanks, I'll dig further into the spec to find the specific clause. Do you know what will happen in the case of a circular dependency? Is it deterministic? – Adam Thompson Nov 16 '18 at 23:33

0 Answers0