Javascript CommonJS模块没有';设置变量的值?

Javascript CommonJS模块没有';设置变量的值?,javascript,node.js,module,synchronous,commonjs,Javascript,Node.js,Module,Synchronous,Commonjs,主文件中的init()函数工作正常,但当我将其放入单独的模块并需要它时,它显然停止工作。我在控制台中得到这个错误 Uncaught TypeError: Failed to set the 'value' property on 'AudioParam': The provided float value is non-finite. 看起来可能是它的同步问题?我怎样才能避开这件事 //init.js file var initt = function () { octaveNumber

主文件中的
init()
函数工作正常,但当我将其放入单独的模块并需要它时,它显然停止工作。我在控制台中得到这个错误

Uncaught TypeError: Failed to set the 'value' property on 'AudioParam': The provided float value is non-finite.
看起来可能是它的同步问题?我怎样才能避开这件事

//init.js file
var initt = function () {
  octaveNumber = document.getElementById("octaveNum");
  audioCtx = new (window.AudioContext || window.webkitAudioContext);
  osc = audioCtx.createOscillator();
  volume = audioCtx.createGain();
  filter = audioCtx.createBiquadFilter();
  osc.connect(filter);
  volume.connect(audioCtx.destination);
  booleanVal = false;
  osc.frequency.value = dial.value
  osc.start();
  gainDisplay.innerHTML = gainSlider.value;
  noteSetOscFreq()
  octaveUpClick()
  octaveDownClick()
  waveFormSelector()
}

module.exports = initt;
主js文件:

if (!localStorage.getItem("presetsArr") {
  messages();
但当我不使用module,只在If语句中使用相同的initt函数时,它就可以正常工作了。如果模块依赖于主js文件中的变量,是否需要在模块中使用主jsfile?就像我调用initt()模块中的其他函数一样。这是个好习惯吗?这是我第一次使用模块系统