最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Uncaught ReferenceError: System is not defined angular 4 - Stack Overflow

matteradmin8PV0评论

I installed angular2-recaptcha in my project ().

I have added 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>

But I am getting this error in browser console:

  Uncaught ReferenceError: System is not defined
    at localhost/:29
piler.es5.js:15996 Uncaught Error: Unexpected module 'ReCaptchaModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation.
    at syntaxError (piler.es5.js:1690)
    at piler.es5.js:15430
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.webpackJsonp.../../../piler/@angular/piler.es5.js.CompileMetadataResolver.getNgModuleMetadata (piler.es5.js:15412)
    at JitCompiler.webpackJsonp.../../../piler/@angular/piler.es5.js.JitCompiler._loadModules (piler.es5.js:26795)
    at JitCompiler.webpackJsonp.../../../piler/@angular/piler.es5.js.JitCompiler._pileModuleAndComponents (piler.es5.js:26768)
    at JitCompiler.webpackJsonp.../../../piler/@angular/piler.es5.js.JitCompilerpileModuleAsync (piler.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)

Please help me! Where is my mistake?

I installed angular2-recaptcha in my project (https://github./xmaestro/angular2-recaptcha).

I have added 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>

But I am getting this error in browser console:

  Uncaught ReferenceError: System is not defined
    at localhost/:29
piler.es5.js:15996 Uncaught Error: Unexpected module 'ReCaptchaModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation.
    at syntaxError (piler.es5.js:1690)
    at piler.es5.js:15430
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.webpackJsonp.../../../piler/@angular/piler.es5.js.CompileMetadataResolver.getNgModuleMetadata (piler.es5.js:15412)
    at JitCompiler.webpackJsonp.../../../piler/@angular/piler.es5.js.JitCompiler._loadModules (piler.es5.js:26795)
    at JitCompiler.webpackJsonp.../../../piler/@angular/piler.es5.js.JitCompiler._pileModuleAndComponents (piler.es5.js:26768)
    at JitCompiler.webpackJsonp.../../../piler/@angular/piler.es5.js.JitCompiler.pileModuleAsync (piler.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)

Please help me! Where is my mistake?

Share Improve this question edited Sep 23, 2017 at 19:37 user663031 asked Sep 23, 2017 at 7:21 Vikram RVikram R 7764 gold badges8 silver badges27 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 3

You need to load SystemJS library, not only the config:

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

Also, System usage is deprecated, use SystemJS whereSystem is global object is expected, for example instead of System.import useSystemJS.import.

Post a comment

comment list (0)

  1. No comments so far