Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2: ReferenceError: webpackJsonp is not defined

I'm new to Ionic. I have started project with super template. But when I try to run the app in browser. It throws an error saying:

ReferenceError: webpackJsonp is not defined
    at http://localhost:8100/build/main.js:1:1

I have tried putting vendor.js in index.html but that has not worked.

Here's the index.html file. I have removed vendor.js as it didn't work.

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8">
  <title>Ionic App</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">

  <link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
  <link rel="manifest" href="manifest.json">
  <meta name="theme-color" content="#4e8ef7">

  <!-- cordova.js required for cordova apps -->
  <script src="cordova.js"></script>

  <!-- un-comment this code to enable service worker
  <script>
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js')
        .then(() => console.log('service worker installed'))
        .catch(err => console.log('Error', err));
    }
  </script>-->

  <link href="build/main.css" rel="stylesheet">

</head>
<body>

  <!-- Ionic's root component and where the app will load -->
  <ion-app></ion-app>

  <!-- The polyfills js is generated during the build process -->
  <script src="build/polyfills.js"></script>

  <!-- The bundle js is generated during the build process -->
  <script src="build/main.js"></script>

</body>
</html>
like image 750
Vishal Singh Avatar asked Jul 08 '17 16:07

Vishal Singh


3 Answers

Literally just went through the same thing as you are. I added the vendor.js script BEFORE the main.js in /src/index.html - now it runs locally.

  <!-- The polyfills js is generated during the build process -->
  <script src="build/polyfills.js"></script>

  <script src="build/vendor.js"></script>

  <!-- The bundle js is generated during the build process -->
  <script src="build/main.js"></script>
like image 151
Eric Winterstine Avatar answered Oct 19 '22 22:10

Eric Winterstine


Add vendor.js path within the script tag in < your application directory > /src/index.html

<script src="build/vendor.js"></script>

Also make changes in < your application directory >/src/service-worker.js File - Include vendor.js in the precache section:

// pre-cache our key assets
self.toolbox.precache(
    [
      './build/main.js',
      './build/vendor.js',   // <===  Add vendor.js
      './build/main.css',
      './build/polyfills.js',
      'index.html',
      'manifest.json'
    ]
);
like image 19
sijo vijayan Avatar answered Oct 20 '22 00:10

sijo vijayan


This is a breaking change in Ionic-App-Scripts

https://github.com/ionic-team/ionic-app-scripts/releases/tag/v2.0.0

src/index.html must be modified to include a new vendor script tag .

...
<body>

  <!-- Ionic's root component and where the app will load -->
  <ion-app></ion-app>

  <script src="cordova.js"></script>

  <!-- The polyfills js is generated during the build process -->
  <script src="build/polyfills.js"></script>

  <!-- all code from node_modules directory is here -->
  <script src="build/vendor.js"></script>

  <!-- The bundle js is generated during the build process -->
  <script src="build/main.js"></script>

</body>
...
like image 59
VRPF Avatar answered Oct 19 '22 22:10

VRPF