简体   繁体   English

来自CDN的angular2加载了我的页面,但是我代码的node_modules中的angular2没有加载

[英]angular2 from a CDN loads my page, but angular2 in my code's node_modules does not

When I use the following CDN in my index.html to provide angular2, my page loads. 当我在index.html中使用以下CDN来提供angular2时,页面就会加载。

<script src="https://code.angularjs.org/2.0.0-alpha.47/angular2.dev.js"></script>

I have the same alpha.47 version in my code in the node_modules directory. 我在node_modules目录中的代码中具有相同的alpha.47版本。 That directory is directly below the angular2-oPost directory containing index.html. 该目录位于包含index.html的angular2-oPost目录的正下方。 When I replace the CDN script with 当我将CDN脚本替换为

<script src="./angular2-oPost/node_modules/angular2/angular2.js"></script>

the page no longer loads. 该页面不再加载。

Console errors start with an error referring to angular2 code: 控制台错误以引用angular2代码的错误开头:

ReferenceError: require is not defined    angular2.js: 4:1
http://localhost/angular2-oPost/angular2/angular2.js    404 not found

then there are many not founds starting with http://localhost/angular2-oPost/angular2/ . 那么从http:// localhost / angular2-oPost / angular2 /开始有很多未找到的内容。 . .

The reference error is in Google's code. 参考错误在Google的代码中。 The 404 says something is looking for angular2 in a directory that does not exist. 404提示某些内容正在不存在的目录中寻找angular2。 Is angular2.js looking for something else. 是angular2.js在寻找其他东西。 What should I change? 我应该改变什么?

Like Eric said you were pointing to the wrong file, you need to point to: 就像Eric所说的那样,您指向错误的文件,您需要指向:

node_modules/angular2/bundles/angular2.js node_modules / angular2 /捆绑/ angular2.js

or 要么

node_modules/angular2/bundles/angular2.dev.js node_modules / angular2 /捆绑/ angular2.dev.js

The purpose of them its obvious in the name itself, angular2.dev.js its meant to be used in development environment, and the other one for production. 它们的目的在名称本身中很明显,angular2.dev.js的意图是在开发环境中使用,另一个用于生产。

I don't know all the exact differences between them though, I believe the main idea was to do less detail in the error logging but I have not noticed it myself yet, not that I have paid too much attention. 我不知道它们之间的所有确切区别,我相信主要思想是减少错误日志记录中的细节,但我本人还没有注意到这一点,不是我太在意。

Also check: 还要检查:
- https://github.com/angular/angular/issues/3458 -https://github.com/angular/angular/issues/3458
- angular2.js vs angular2.dev.js -angular2.js和angular2.dev.js

Looks like the proposal of what it "should" be, but the thing being in "beta" that looks like epsilon and all it might not be true, or at least not yet. 看起来像“应该”是什么的建议,但是“ beta”中看起来像epsilon的东西可能不是真的,或者至少不是真的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM