【问题标题】:Unresolved function or method for pipe()pipe() 的未解析函数或方法
【发布时间】:2017-04-07 03:57:46
【问题描述】:

我正在尝试编写一个简单的文件网络文件服务器。我正在使用 PhpStorm。

var http = require('http');

var fs = require('fs');

function send404Request(response) {
    response.writeHead("404", {"Content-Type": "text/html"});
    response.write("404 Page Not Found");
    response.end();
}

function onRequest(request, response) {
    if (request.method === 'GET' && request.url === '/') {
        response.writeHead("200", {"Content-Type": "text/plain"});
        fs.createReadStream("./index.html").pipe(response);
    } else {
        send404Request(response);
    }
}


http.createServer(onRequest).listen(8888);
console.log("file server is now running...");

但是,PhpStorm 说“未解析的函数或方法 pipe()”

这是我在 PhpStorm 中对 JavaScript 库的设置:

知道哪里出错了吗?

【问题讨论】:

  • 这是新的波士顿教程,哈哈,现在完全相同的问题

标签: node.js pipe phpstorm webstorm


【解决方案1】:

在 Settings/Project Settings/JavaScript/Libraries 中,下载“node-DefinitelyTyped”。这对我有用。我遇到了和你一样的问题。

【讨论】:

  • 如果没有其他工作,我更新到最新版本的 Webstorm 并且成功了
【解决方案2】:

也许您需要等待流打开:

var readStream = fs.createReadStream("./index.html");

readStream.on('open', function () {
    readStream.pipe(response);
});

此外,添加这个以捕获可能发生的任何错误:

readStream.on('error', function(err) {
    console.log(err.message);
});

【讨论】:

    【解决方案3】:

    在 2019 年底遇到了同样的问题,但在我的 gulpfile.js 中。

    • 我得到了“未解析的函数或方法 pipe()”并且
    • PHPStorm 中的“Unresolved function or method require()”错误消息。

    在 PHPStorm 中下载 @types/gulp 库解决了这两个问题。

    【讨论】:

      【解决方案4】:

      这是我正在使用的解决方法。代替 fs.createReadStream("./index.html").pipe(response);

      我正在使用: response.write(fs.readFileSync("./index.html"));

      这适用于 intelliJ IDEA

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-24
        • 1970-01-01
        • 2022-12-03
        • 2014-03-01
        • 2019-01-10
        • 1970-01-01
        • 1970-01-01
        • 2018-05-02
        相关资源
        最近更新 更多