[英]Angular2 import path wrong at runtime
I have an angular2 app and at runtime it tries to load a resource from the wrong URL. 我有一个angular2应用程序,并在运行时它尝试从错误的URL加载资源。
It should look for it at: http://localhost:54675/app/services/angular2-jwt.js , but it looks for it at: http://localhost:54675/app/ shared /services/angular2-jwt.js. 它应该在以下地址查找: http:// localhost:54675 / app / services / angular2-jwt.js ,但它在以下地址查找: http:// localhost:54675 / app / shared / services / angular2-jwt。 JS。 The word shared should not be in the path.
共享这个词不应该在路径中。
I have this structure in angular2: 我在angular2中有这个结构:
app
---services
------angular2-jwt.ts
---shared
------country
---------country.service.ts
In country.service.ts I reference angular2-jwt.ts like this: 在country.service.ts中,我像这样引用angular2-jwt.ts:
import {AuthHttp} from '../../services/angular2-jwt';
As you can see, that's up two (into app) and down into services. 正如你所看到的,这是两个(进入应用程序)和进入服务。 It should give this path: app/services/angular2-jwt.
它应该给这个路径:app / services / angular2-jwt。 I look in the compiled js at looks correct:
看起来在编译的js看起来正确:
System.register(['angular2/core', '../../services/angular2-jwt']
I am using Visual Studio and the intelliSense works. 我正在使用Visual Studio和intelliSense工作。 I see AuthHttp in a popup as an option from that library.
我在弹出窗口中看到AuthHttp作为该库的一个选项。 I don't get an error when I save or build.
我保存或构建时没有出错。 I think this is correct.
我认为这是正确的。
At runtime I get this error in the broswer console: 在运行时,我在broswer控制台中收到此错误:
Error: Unable to load script: http://localhost:54675/app/shared/services/angular2-jwt.js
Notice the script URL path is wrong. 请注意脚本URL路径错误。 It has 'shared' as part of the path but should not.
它作为路径的一部分“共享”但不应该。
I have caching disabled in my browser. 我在浏览器中禁用了缓存。 I look at the js source in the browser and I see that same source mentioned above.
我在浏览器中查看js源代码,我看到上面提到的相同来源。 It happens in chrome (my default) and Firefox (which I rarely use) so I don't think it's a caching issue.
它发生在chrome(我的默认)和Firefox(我很少使用)中,所以我不认为这是一个缓存问题。 How is it getting this path?
怎么走这条路呢?
Here is my SystemJS configuraiton from index.html: 这是我在index.html中的SystemJS配置:
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
I have now duplicated this on another machine. 我现在在另一台机器上复制了这个。 However, I am importing this same module ('../../services/angular2-jwt') from a different file at a similar locaiton is the directory tree and it works.
但是,我从类似位置的不同文件导入同一个模块('../../services/angular2-jwt')是目录树,它可以工作。
Check the import path to all components, not just this one. 检查所有组件的导入路径,而不仅仅是这个组件。 I had bad syntax in a parent component and it caused this issue.
我在父组件中的语法错误,导致了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.