【发布时间】:2018-05-17 03:38:31
【问题描述】:
我有一个快速应用程序调用 Angular2 应用程序。我一直收到 Error: (SystemJS) Unexpected token
我发现 app.module.js 返回的是 html 而不是 .js,这是导致代码丢失的原因吗?
Error: (SystemJS) Unexpected token <
详细错误是:
dashboard:21 Error: (SystemJS) Unexpected token <
SyntaxError: Unexpected token <
at eval (<anonymous>)
at Object.eval (http://localhost:3000/main.js:3:20)
at eval (http://localhost:3000/main.js:8:4)
at eval (http://localhost:3000/main.js:9:3)
Evaluating http://localhost:3000/app/app.module.js
Evaluating http://localhost:3000/main.js
Error loading http://localhost:3000/main.js
at eval (<anonymous>)
at Object.eval (http://localhost:3000/main.js:3:20)
at eval (http://localhost:3000/main.js:8:4)
at eval (http://localhost:3000/main.js:9:3)
Evaluating http://localhost:3000/app/app.module.js
Evaluating http://localhost:3000/main.js
Error loading http://localhost:3000/main.js
这就是我的快递的样子:
app.use('/styles.css', express.static(path.join(__dirname, '../angular/src/styles.css')));
app.use('/systemjs.config.js', express.static(path.join(__dirname, '../angular/src/systemjs.config.js')));
app.use('/systemjs-angular-loader.js', express.static(path.join(__dirname, '../angular/src/systemjs-angular-loader.js')));
app.use('/systemjs.config.extras.js', express.static(path.join(__dirname, '../angular/src/systemjs.config.extras.js')));
app.use('/main.js.map', express.static(path.join(__dirname, '../angular/src/main.js.map')));
app.use('/main.js', express.static(path.join(__dirname, '../angular/src/main.js')));
app.use(express.static(path.join(__dirname, '../angular')));
app.use('/api/', auditlog);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../angular/src/index.html'));
});
【问题讨论】:
-
app.module.js不太可能返回 HTML。这很可能是以下两种情况之一:要么您的路由器没有路由您的请求并退回到发送index.html,要么您的 API 返回 HTML 而不是 JSON。 -
嗨兰迪,我认为你是对的。我的快递应用程序是否需要知道哪些路线要发送到 Angular?最后一行 app.get('*')... 是否不足以指示查询从 Angular 返回正确的组件?
-
@RandyCasburn 而不是 JSON**
-
@MotassemMK - 我们现在真的是在拼词吗?见:dictionary.com/browse/in--lieu--of
-
@RustySchmidt - 请分享您使用的 URL,并希望从您的 Express 服务器获取 JSON。
标签: javascript angular express systemjs