[英]System.config is not defined
Hi I don't know why I have this error when I want configure my angular project :嗨,当我想配置我的 angular 项目时,我不知道为什么会出现此错误:
System.config is not a funtion
My package.json & html :我的 package.json 和 html :
{ "name": "", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \\"Error: no test specified\\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "@angular/common": "^5.2.0", "@angular/compiler": "^5.2.0", "@angular/core": "^5.2.0", "@angular/platform-browser": "^5.2.0", "@angular/platform-browser-dynamic": "^5.2.0", "reflect-metadata": "^0.1.12", "rxjs": "^5.5.0", "systemjs": "^2.0.2", "zone.js": "^0.8.26" }, "devDependencies": { "@types/core-js": "^2.5.0" } }
<html> <head> <script src="node_modules/zone.js/dist/zone.js"></script> <script src="node_modules/reflect-metadata/Reflect.js"></script> <script src="node_modules/systemjs/dist/system.js"></script> <script> System.config({ // the app will need the following dependencies map: { '@angular/core': 'node_modules/@angular/core/bundles/core.umd.js', '@angular/common': 'node_modules/@angular/common/bundles/common.umd.js', '@angular/compiler': 'node_modules/@angular/compiler/bundles/compiler.umd.js', '@angular/platform-browser': 'node_modules/@angular/platformbrowser/bundles/platform-browser.umd.js', '@angular/platform-browser-dynamic': 'node_modules/@angular/platform-browserdynamic/bundles/platform-browser-dynamic.umd.js', 'rxjs': 'node_modules/rxjs' }, packages: { // we want to import our modules without writing '.js' at the end // we declare them as packages and SystemJS will add the extension for us '.': {} } }); // and to finish, let's boot the app! System.import('main'); </script> </head> <body> <home> Hello </home> </body> </html>
I think is the version of systemJS is to recent but I don't know more....我认为 systemJS 的版本是最近的,但我不知道更多....
Is the configuration of SystemJs changed in the latest versions? SystemJs 的配置在最新版本中是否有变化?
There seems to be some problem with the latest version of systemjs
, you can downgrade it to "0.21.3"
version and you will see everything will work just fine.最新版本的
systemjs
似乎有些问题,您可以将其降级到"0.21.3"
版本,您会看到一切正常。
Checkout angular6-without-cli working repo here.在此处结帐angular6-without-cli工作仓库。
Note: Make sure you do
npm install
before give it a try.注意:请确保在尝试之前执行
npm install
。
It looks like the SystemJS 2 way to do this, is to put the config (as valid JSON) in a block like so:看起来 SystemJS 2 的方法是将配置(作为有效的 JSON)放在一个块中,如下所示:
<script type="systemjs-packagemap">
{
"map": {
"@angular/core": "node_modules/@angular/core/bundles/core.umd.js",
"@angular/common": "node_modules/@angular/common/bundles/common.umd.js",
"@angular/compiler": "node_modules/@angular/compiler/bundles/compiler.umd.js",
"@angular/platform-browser": "node_modules/@angular/platformbrowser/bundles/platform-browser.umd.js",
"@angular/platform-browser-dynamic": "node_modules/@angular/platform-browserdynamic/bundles/platform-browser-dynamic.umd.js",
"rxjs": "node_modules/rxjs"
},
"packages": {
"main": "../main.js"
}
}
</script>
<script src="node_modules/systemjs/dist/system.js"></script>
<script>
System.import('main');
</script>
Please note, this has to be placed before the system.js script请注意,这必须放在 system.js 脚本之前
More details can be found in their docs更多细节可以在他们的文档中找到
I guess you would have upgraded to the latest system.js by mistake... which doe not support System.Config Refer to https://guybedford.com/systemjs-2.0我猜你会错误地升级到最新的 system.js... 不支持 System.Config 参考https://guybedford.com/systemjs-2.0
It is instead done using https://github.com/systemjs/systemjs/blob/2.0.0/docs/package-name-maps.md它是使用https://github.com/systemjs/systemjs/blob/2.0.0/docs/package-name-maps.md完成的
If you managed to update the code by now, might as well post the updated sample here for use of everyone.如果您现在设法更新了代码,不妨在此处发布更新后的示例供大家使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.