2017-09-23 112 views
3

我在我的项目(https://github.com/xmaestro/angular2-recaptcha)中安装了angular2-recaptcha。Uncaught ReferenceError:系统未定义角度4

我已经加入systemjs.config.js

System.config({ 
    map: { 
    'angular2-recaptcha': 'node_modules/angular2-recaptcha' 
    }, 
    packages: { 
    app: { 
     format: 'register', 
     defaultExtension: 'js' 
    }, 
    'angular2-recaptcha': {defaultExtension: 'js', main:'index'} 
    } 
}); 

的index.html

<script src="systemjs.config.js"></script> 
<script> 
System.import('app').catch(function(err){ 
    console.error(err); 
}); 
</script> 

但我得到这个错误在浏览器控制台:

Uncaught ReferenceError: System is not defined 
    at localhost/:29 
compiler.es5.js:15996 Uncaught Error: Unexpected module 'ReCaptchaModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation. 
    at syntaxError (compiler.es5.js:1690) 
    at compiler.es5.js:15430 
    at Array.forEach (<anonymous>) 
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:15412) 
    at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._loadModules (compiler.es5.js:26795) 
    at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._compileModuleAndComponents (compiler.es5.js:26768) 
    at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler.compileModuleAsync (compiler.es5.js:26697) 
    at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_._bootstrapModuleWithZone (core.es5.js:4536) 
    at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_.bootstrapModule (core.es5.js:4522) 
    at Object.../../../../../src/main.ts (main.ts:11) 

请帮帮我!我的错误在哪里?

回答

1

你需要下载SystemJS库,不仅配置:

<script src="systemjs/dist/system.js"></script> <--------------------- 
<script src="systemjs.config.js"></script> 
<script> 
    System.import('app').catch(function(err){ console.error(err); }); 
</script> 

此外,System用法已过时,使用SystemJS其中System是全局对象的预期,例如,而不是使用System.importSystemJS.import

相关问题