我一直在开发一个 Angular 2 应用程序,我从 Angular2 快速启动应用程序下载了该应用程序。当我运行并构建应用程序时,它显示 require 未定义。
Uncaught ReferenceError: require is not defined
下面是我如何包含 system.js 的代码
//index.html
<!DOCTYPE html>
<html>
<head>
<title>Angular QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="app/styles/main.css">
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
最佳答案
当您尝试使用 commonjs 构建并尝试使用 systemjs 加载器加载时,会发生这种情况。在 tsconfig.json 中将模块更改为系统。
下面是我的 tsconfig.json。
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
关于angular - 使用常见的 TypeScript 构建无法找到 require,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39924432/