Angular2 5 minute install bug - require is not defined

后端 未结 7 1710
一个人的身影
一个人的身影 2020-11-28 12:22

I\'m doing the Angular2 5 minute quick start.

About half way through the tutorial now, I have the following files setup correctly:

  • index.html,
7条回答
  •  佛祖请我去吃肉
    2020-11-28 13:08

    If you are following the Upgrade to Angular2 tutorial, this may bite you:

    Make sure you are not still manually loading your converted javascript files when you convert the files to typescript and use the module loaders to load them.

    I had converted some files to TS, but was still loading the original (now transpiled) JS files in the index.html. If you do this, you'll keep getting "require is not defined" because the "require" library hasn't been loaded yet.

    Bottom line: So, if you get "require is not defined" put a debugger statement before the offending line (for me, it was import { Injectable } from '@angular/core' ), look at what source files have been loaded and make sure you're not still loading the file manually.

提交回复
热议问题