简体   繁体   English

Angular 2“未定义需求”

[英]Angular 2 “require is not defined”

I am working on an app, which previously worked. 我正在开发一个以前有效的应用程序。 I am now trying to add some routing, so have created an app.component file and changed a few parameters, but now I just get a blank screen and this error in the console... 我现在正在尝试添加一些路由,因此创建了一个app.component文件并更改了一些参数,但是现在我只得到了一个空白屏幕,并且控制台中出现此错误...

Error: ReferenceError: require is not defined
        at eval (http://localhost:3000/client/dev/main.js:2:17)
        at eval (http://localhost:3000/client/dev/main.js:6:3)
        at $ (http://localhost:3000/node_modules/systemjs/dist/system-polyfills.js:4:8740)
    Evaluating http://localhost:3000/client/dev/main.js
    Error loading http://localhost:3000/client/dev/main.js

在此处输入图片说明 My Main.JS file is: 我的Main.JS文件是:

"use strict";
var browser_1 = require('angular2/platform/browser');
var app_component_1 = require('./app.component');
browser_1.bootstrap(app_component_1.AppComponent);

This is Generated from main.ts : 这是从main.ts生成的:

import { bootstrap }    from 'angular2/platform/browser';
import { AppComponent } from './app.component';

bootstrap(AppComponent);

Whats's wrong with this? 这怎么了

Update: 更新:

Thanks Eric for your suggestion about using the system module in tsconfig.json, but if I do it, I get the following error: 感谢Eric对于您在tsconfig.json中使用系统模块的建议,但如果这样做,则会出现以下错误:

C:\Users\George\Source\Repos\Gen-App\server\server.js:2
System.register(['express', 'os', 'http', './config/routes.conf', './config/db.conf', './config/passport', './routes/index'], function(exports_1, context_1) {
^

ReferenceError: System is not defined
    at Object.<anonymous> (C:\Users\George\Source\Repos\Gen-App\server\server.js:2:1)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (C:\Users\George\Source\Repos\Gen-App\index.js:1:63)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)

NB: my server.js code is here 注意:我的server.js代码在这里

You say you added some routing and now it's not working. 您说添加了一些路由,但现在不起作用。 Your index.html file needs to include the router.dev.js file: 您的index.html文件需要包含router.dev.js文件:

<script src="node_modules/angular2/bundles/router.dev.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM