为什么找不到现有的 JavaScript 函数生成 Uncaught ReferenceError

Why is an existing JavaScript function not found generating Uncaught ReferenceError

错误:

readyException.js:6 Uncaught ReferenceError: editMap is not defined
    at HTMLDocument.<anonymous> (edit:190)
    at mightThrow (deferred.js:97)
    at process (deferred.js:139)

来自 Chrome 来源的页面(popupText 由 Rails 生成):

  <div id="map"></div>
  <script>
    var popupText = "&ge;1908<br>Benefit  St<br>&le;1908<br>Fountain Ave";
    $(document).ready(function() {
       editMap(popupText);
    });    
  </script>

来自 Chrome 来源

application.js 的一些相关行
function editMap(popupText) {
  if (laMap != undefined) {
    laMap.remove();
  }
  showMap(popupText)
  var drawnItems = new L.FeatureGroup();

正在尝试将应用程序移动到 Rails 6 和 webpacker。

Webpack 不会将您的 JavaScript 暴露给全局范围;每个文件都被视为一个模块,实际上,它是一个具有自己范围的函数。要公开对全局范围的特定引用,您可以将其分配给模块中的 window 对象,例如 window.editMap = editMap