Answer the question
In order to leave comments, you need to log in
How to defeat "initMap is not a function" when using webpack and babel?
Hello. I'm trying to use the webpack assembly with babel, but in this case, for some reason, the initmap function for googlemaps does not work.
<script type="text/javascript" src="./js/bundle.js"></script>
<script type="text/javascript" async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDgD9raCgCP3YPNgS7DZyoB8t-Q8wCuaRY&callback=initMap"></script>
//Google Maps init
function initMap() {
var e = {
lat: 40.714909,
lng: -73.751213
}
, t = new google.maps.Map(document.getElementById("map"), {
zoom: 16,
center: e
});
new google.maps.Marker({
position: e,
map: t
})
}
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./src/js/index.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./src/js/index.js":
/*!*************************!*\
!*** ./src/js/index.js ***!
\*************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
//Google Maps init
function initMap() {
var e = {
lat: 40.714909,
lng: -73.751213
},
t = new google.maps.Map(document.getElementById("map"), {
zoom: 16,
center: e
});
new google.maps.Marker({
position: e,
map: t
});
}
Answer the question
In order to leave comments, you need to log in
webpack.config.js
entry: 'entry.js',
output: {
filename: 'bundle.js',
library: 'App'
},
function initMap() {
var e = {
lat: 40.714909,
lng: -73.751213
}
, t = new google.maps.Map(document.getElementById("map"), {
zoom: 16,
center: e
});
new google.maps.Marker({
position: e,
map: t
})
}
export {
initMap,
};
<script type="text/javascript" src="./js/bundle.js"></script>
<script>
//Google Maps init
function initMap() {
var e = {
lat: 40.714909,
lng: -73.751213
}
, t = new google.maps.Map(document.getElementById("map"), {
zoom: 16,
center: e
});
new google.maps.Marker({
position: e,
map: t
})
}
</script>
<script type="text/javascript" async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDgD9raCgCP3YPNgS7DZyoB8t-Q8wCuaRY&callback=initMap"></script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question