Javascript 离子 2: ReferenceError: webpackJsonp 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44988166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:50:29  来源:igfitidea点击:

Ionic 2: ReferenceError: webpackJsonp is not defined

javascriptionic-frameworkwebpack

提问by Vishal Singh

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:

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

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.

我曾尝试将 vendor.js 放在 index.html 中,但没有奏效。

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

这是 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>

回答by Eric Winterstine

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.

从字面上看,您刚刚经历了与您相同的事情。我在 /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>

回答by VRPF

This is a breaking change in Ionic-App-Scripts

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

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

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 .

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>
...

回答by sijo vijayan

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

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

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

Also make changes in < your application directory >/src/service-worker.jsFile - Include vendor.jsin the precachesection:

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

// 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'
    ]
);

回答by Kishan Oza

I face the same issue when i started developing old ionic 2 project with ionic 3. follow this steps works for me. opne src\index.htmlput this line

当我开始使用 ionic 3 开发旧的 ionic 2 项目时,我遇到了同样的问题。请按照以下步骤操作。opnesrc\index.html把这条线

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

before

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

and after

之后

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

like this

像这样

<!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>

回答by Dinesh

Ionic version problem bro.

离子版本问题兄弟。

check the version.

检查版本。

npm install -g [email protected]
npm install -g [email protected]
npm install -g ionic@v1

回答by yacine benzmane

npm install -g [email protected]

or

或者

yarn add -g [email protected]

回答by RBT

I was working on a ReactJs project when I faced this error. This could be a case of missing dependencies from package.jsonfile which eventually bubbles up in the form of error reported by OP. In our case a reference to omitJsnpm package was missing. The moment I added below line in dependencies section of package.jsonfile it all started to work:

当我遇到这个错误时,我正在处理一个 ReactJs 项目。这可能是package.json文件中缺少依赖项的情况,最终以 OP 报告的错误形式冒泡。在我们的例子中,缺少对omitJsnpm 包的引用。我在package.json文件的依赖项部分添加以下行的那一刻开始工作:

"dependencies": {
.....other dependencies
"omit.js": "1.0.0"
}

回答by gersonmontenegro

I just have faced this issue, and the order of the files polyfills/vendor/main doesn't anything has to do in my case, but it was the size of the vendor.js file.

我刚刚遇到了这个问题,文件 polyfills/vendor/main 的顺序在我的情况下没有任何关系,但它是 vendor.js 文件的大小。

I did realize it because it works on my local machine, so, I did find that vendor.js was 5MB, so, I builded again the app using --prod parameter:

我确实意识到了这一点,因为它可以在我的本地机器上运行,因此,我确实发现 vendor.js 为 5MB,因此,我使用 --prod 参数再次构建了该应用程序:

ionic cordova build ios --prod