gpt4 book ai didi

node.js - Simple Express Server 和 Gulp 出错

转载 作者:太空宇宙 更新时间:2023-11-03 23:08:35 26 4
gpt4 key购买 nike

我正在尝试使用 gulp 任务运行一个简单的 Express Web 服务器。我只想要一个显示索引文件的静态服务器。我可以通过运行 Node 模块轻松执行此操作,但同样,我想在 gulp 中执行此操作。我计划扩展它以允许设置 LiveReload 服务器。

我已经遵循了许多有关设置 LiveReload 的教程,但它们都失败了。我假设这与撰写文章时使用的版本有关。但我希望也许有人知道如何处理这个问题。

我创建了一个非常小的 Github 存储库,让您可以尝试我想要完成的任务:fixit

Gulpfile.js:

var gulp = require('gulp');

var EXPRESS_PORT = 4000;
var EXPRESS_ROOT = __dirname;

gulp.task('express', function () {
var express = require('express');
var app = express();
app.use(express.static(EXPRESS_ROOT));
app.listen(EXPRESS_PORT);
});

*与Gulpfile在同一目录下有一个index.html

这是错误:

/var/www/clients/client1/web14/sendus-admin/node_modules/express/node_modules/etag/index.js:55
throw new TypeError('argument entity must be string or Buffer')
^
TypeError: argument entity must be string or Buffer
at etag (/var/www/clients/client1/web14/sendus-admin/node_modules/express/node_modules/etag/index.js:55:11)
at SendStream.setHeader (/var/www/clients/client1/web14/sendus-admin/node_modules/express/node_modules/send/index.js:724:15)
at SendStream.send (/var/www/clients/client1/web14/sendus-admin/node_modules/express/node_modules/send/index.js:500:8)
at onstat (/var/www/clients/client1/web14/sendus-admin/node_modules/express/node_modules/send/index.js:585:10)
at Object.oncomplete (fs.js:97:15)

最佳答案

我遇到了同样的问题,在 Gulp 和 BrowserSync 工作一周后(这两个组合给我带来了同样的错误),我采取了更严重的选项,例如重新安装 Node.js。最后,对我有用的是使用 nvm 降级到 Node.js 版本 10(我之前使用的是 11)。

nvm install 0.10
nvm use 0.10

然后刚刚更新并使用 Gulp:

npm update
gulp

当然希望对你也有帮助。

关于node.js - Simple Express Server 和 Gulp 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25770655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com