【发布时间】:2019-02-01 08:51:49
【问题描述】:
我已经分别使用angular-cli 和express 命令行设置了一个角度和快速应用程序。我已经使用ng build 构建了 Angular 应用程序,当我想通过快速服务器为其提供服务时,我在 google chrome 控制台中收到以下错误:
Uncaught SyntaxError: Unexpected token < runtime.js:1
Uncaught SyntaxError: Unexpected token < polyfills.js:1
Uncaught SyntaxError: Unexpected token < styles.js:1
Uncaught SyntaxError: Unexpected token < vendor.js:1
Uncaught SyntaxError: Unexpected token < main.js:1
这是我的 server.js 文件:
.
.
.
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/users', usersRouter);
app.use('/auth', authRouter);
// Catch all other routes and return the angular index file
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/dist/client/index.html'));
});
index.html 文件:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Client</title>
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="runtime.js"></script>
<script type="text/javascript" src="polyfills.js"></script>
<script type="text/javascript" src="styles.js"></script>
<script type="text/javascript" src="vendor.js"></script>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
ng serve 没有问题,应用程序将运行顺利,而且当我用浏览器打开 index.html 时它也可以工作,我认为它在某种程度上与快递服务器有关。
【问题讨论】:
-
您在 index.html 中包含的五个 JS 文件(runtime、polyfills、styles、vendor 和 main)存储在哪个目录?
-
@thmsdnnr 与“index.html”相同。它们都在“client/dist/client/”目录下。
标签: javascript node.js angular express