为什么我的所有脚本都以MIME类型text / html的形式传输?

时间:2014-08-18 14:02:15

标签: javascript node.js angularjs gruntjs mime-types

我在一个大型node.js / Angular.js应用程序上工作。我们使用grunt重新编译公共脚本和标记。大多数时候,我在本地运行服务器没有问题。每次进行更改时,我都会运行grunt dev,然后使用npm start启动服务器。如果我的代码出现问题,grunt会抓住它并在启动服务器之前警告我。但是,每隔一段时间,我运行我的命令,刷新页面,并且我的所有数十个脚本都以MIME类型text / html而不是text / javascript的形式传输,并且页面不会加载任何内容。

Uncaught SyntaxError: Unexpected token < app.js:1
Uncaught SyntaxError: Unexpected token < environment-provider.js:1
Uncaught SyntaxError: Unexpected token < promise-service.js:1
Resource interpreted as Script but transferred with MIME type text/html:"http://localhost:3083/components/underscore/underscore.js". (index):62
Uncaught SyntaxError: Unexpected token < underscore.js:1
Resource interpreted as Script but transferred with MIME type text/html:"http://localhost:3083/components/spinner-button/spinner-button.js". (index):64
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3083/components/util/sa-util.js". (index):63
Uncaught SyntaxError: Unexpected token < sa-util.js:1
Uncaught SyntaxError: Unexpected token < spinner-button.js:1
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3083/bower_components/sport-ng/deferred/deferred-directive.js". (index):68
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3083/bower_components/sport-ng/datepicker/datepickerDirective.js". (index):69
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3083/bower_components/sport-ng/alerts/alertsService.js". (index):66
Uncaught SyntaxError: Unexpected token < alertsService.js:1
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3083/bower_components/sport-ng/confirmDelete/confirmDeleteService.js". (index):67

当我在Chrome开发工具中打开其中一个脚本文件时,它会向我显示我的public / layout.html文件中的任何内容。这个问题持续了一段时间(通常是一天的剩余时间),我通过切换到新目录并从github重新克隆来避免它。当我稍后切换回该目录时,问题通常会消失。最近,我变得更加绝望。问题是现在以某种方式跟随我之间的目录,我不明白是什么触发了这个或如何阻止它。将type="text/javascript"添加到我的脚本标记似乎没有帮助,我似乎无法重新创建问题。从小小的我已经能够在论坛上挖掘,似乎这是一个角度问题。

我们用来组织应用和提供文件的node.js框架是Nokomis。布局文件由grunt动态生成,以包含此应用程序使用的一组模块。但是,Grunt只更新了这些模块的路径。其余的Angular文件都提供简单的脚本引用。

<script src="/components/environment/environment-provider.js"></script>
<script src="/components/promise/promise-service.js"></script>
<script src="/components/underscore/underscore.js"></script>
<script src="/components/util/sa-util.js"></script>
<script src="/components/spinner-button/spinner-button.js"></script>

来自package.json:

"grunt": "0.4.1",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-compass": ">=0.1.3",
"grunt-contrib-copy": "0.4.x",
"grunt-contrib-jshint": "0.7.x",
"grunt-contrib-watch": "0.2.x",
"grunt-exec": "0.4.x",
...
"engines": {
"node": ">=0.8.0",
"npm": ">=1.1.21"
},

有没有人就如何解决或预防此问题提出建议?

0 个答案:

没有答案