错误:Angular 2

时间:2018-03-26 16:05:11

标签: angular systemjs

我对Angular比较新,我正在尝试使用Angular2,NodeJs,Express和MongoDB构建一个MEAN应用程序。我一直在关注一个有点旧的教程,所以有些说明已经过时了。 所以我使用了Angular的快速入门指南来设置它。

在我的index.html文件中,我有以下行System.import('app').then (null, console.error.bind(console));,结果为Error: (SystemJS) require is not defined

以下代码,如果来自我的systemjs.config.js文件。

    System.import('app').then (null, console.error.bind(console));`
which gives me the error `Error: (SystemJS) require is not defined`. 
The problem is inside the systemjs/index.js file, as I am using this in the nodemodules on the front end. 

I have been looking for a solution to my problem for a couple of days now, and people suggest that I use a bundle or an import statement, but I am unsure about the syntax I need to use. 
Here is the code that is giving me the issue:
if (typeof Promise === 'undefined')
  require('when/es6-shim/Promise');

var version = require('./package.json').version;

var isWindows = typeof process.platform != 'undefined' && process.platform.match(/^win/);

// set transpiler paths in Node
var nodeResolver = typeof process != 'undefined' && typeof require != 'undefined' && require.resolve;
function configNodePath(loader, module, nodeModule, wildcard) {
  if (loader.paths[module])
    return;

  var ext = wildcard ? '/package.json' : '';
  try {
    var match = nodeResolver(nodeModule + ext).replace(/\\/g, '/');
  }
  catch(e) {}

  if (match)
    loader.paths[module] = 'file://' + (isWindows ? '/' : '') + match.substr(0, match.length - ext.length) + (wildcard ? '/*.js' : '');
}

var SystemJSLoader = require('./dist/system.src').constructor;

// standard class extend SystemJSLoader to SystemJSNodeLoader
function SystemJSNodeLoader() {
  SystemJSLoader.call(this);

  if (nodeResolver) {
    configNodePath(this, 'traceur', 'traceur/bin/traceur.js');
    configNodePath(this, 'traceur-runtime', 'traceur/bin/traceur-runtime.js');
    configNodePath(this, 'babel', 'babel-core/browser.js');
    configNodePath(this, 'babel/external-helpers', 'babel-core/external-helpers.js');
    configNodePath(this, 'babel-runtime/*', 'babel-runtime', true);
  }
}
SystemJSNodeLoader.prototype = Object.create(SystemJSLoader.prototype);
SystemJSNodeLoader.prototype.constructor = SystemJSNodeLoader;

var System = new SystemJSNodeLoader();

System.version = version + ' Node';

if (typeof global != 'undefined')
  global.System = global.SystemJS = System;

module.exports = System;

我尝试过更新我的npm,打字稿甚至是angular-cli。我还更改了tsconfig.app.json文件中的'module',并将format: 'register'添加到了我的systemjs.config.js文件中。

任何帮助都将受到高度赞赏,请提前感谢。

0 个答案:

没有答案