【问题标题】:Node gives error : 'Module not found' even after installing it节点给出错误:“模块未找到”即使在安装后也是如此
【发布时间】:2021-03-23 13:52:24
【问题描述】:

我正在尝试在节点上运行此脚本,除了标准库之外,它还需要模块:多方

var multiparty = require('multiparty');
var http = require('http');
var util = require('util');

http.createServer(function(req, res) {
  if (req.url === '/upload' && req.method === 'POST') {
    // parse a file upload
    var form = new multiparty.Form();

    form.parse(req, function(err, fields, files) {
      res.writeHead(200, { 'content-type': 'text/plain' });
      res.write('received upload:\n\n');
      res.end(util.inspect({ fields: fields, files: files }));
    });

    return;
  }

  // show a file upload form
  res.writeHead(200, { 'content-type': 'text/html' });
  res.end(
    '<form action="/upload" enctype="multipart/form-data" method="post">'+
    '<input type="text" name="title"><br>'+
    '<input type="file" name="upload" multiple="multiple"><br>'+
    '<input type="submit" value="Upload">'+
    '</form>'
  );
}).listen(8080);

我使用的脚本是多方文档给出的官方示例。 由于我在节点的 REPL 模式下运行此脚本,因此我决定首先使用此命令全局安装多方

npm install -g multiparty

模块已安装,之后我尝试在节点上运行它,但上传文件时出现以下错误,即localhost:8080/upload

Uncaught TypeError : Cannot read property 'Form' of undefined

还有一个Module Not found 错误,如下所示

我也尝试使用以下命令安装多方

npm install multiparty

但错误仍然存​​在。

【问题讨论】:

标签: node.js import node-modules


【解决方案1】:

我查看了NPM global install "cannot find module" 中的答案,发现我的环境变量NODE_PATH 没有设置,应该设置为C:\Users\%USER_PROFILE%\AppData\Roaming\npm\node_modules

【讨论】:

    猜你喜欢
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    • 2018-03-08
    • 2019-10-02
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多