Ionic 2:ReferenceError:未定义webpackJsonp

Vis*_*ngh 51 javascript ionic-framework webpack

我是Ionic的新手.我已经用超级模板开始了项目.但是当我尝试在浏览器中运行应用程序时.它抛出一个错误说:

ReferenceError: webpackJsonp is not defined
    at http://localhost:8100/build/main.js:1:1
Run Code Online (Sandbox Code Playgroud)

我已经尝试将vendor.js放在index.html中但是没有用.

这是index.html文件.我删除了vendor.js因为它不起作用.

<!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>
Run Code Online (Sandbox Code Playgroud)

小智 110

字面上只是和你一样经历过同样的事情.我在/src/index.html中的main.js之前添加了vendor.js脚本- 现在它在本地运行.

  <!-- 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>
Run Code Online (Sandbox Code Playgroud)

  • 这应该是公认的答案,因为这是错误的原因 (6认同)
  • 这适用于较新的Android版本.但是,当我在我的Android 4.4.4上测试它不起作用.仍然是同样的错误:( (2认同)

VRP*_*RPF 56

这是Ionic-App-Scripts的一个重大变化

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

必须修改src/index.html以包含新的供应商脚本标记.

...
<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>
...
Run Code Online (Sandbox Code Playgroud)


sij*_*yan 17

vendor.js在脚本标记中添加路径< your application directory > /src/index.html

<script src="build/vendor.js"></script>
Run Code Online (Sandbox Code Playgroud)

还可以在< your application directory >/src/service-worker.js文件中进行更改- 包含vendor.js 在以下precache部分中:

// 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'
    ]
);
Run Code Online (Sandbox Code Playgroud)


Kis*_*Oza 16

当我开始用离子3开发旧的离子2项目时,我面临同样的问题.按照这个步骤适合我.opne src\index.html 把这条线

<script src="build/vendor.js"></script>
Run Code Online (Sandbox Code Playgroud)

之前

<script src="build/main.js"></script>
Run Code Online (Sandbox Code Playgroud)

之后

<script src="build/polyfills.js"></script>
Run Code Online (Sandbox Code Playgroud)

像这样

<!DOCTYPE html>
...
<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>
  <script src="build/vendor.js"></script>  <---- here
  <!-- The bundle js is generated during the build process -->
  <script src="build/main.js"></script>

</body>

</html>
Run Code Online (Sandbox Code Playgroud)