简体   繁体   English

Node.js mailparser模块错误:找不到模块'iconv'

[英]Node.js mailparser module error: Cannot find module 'iconv'

I'm working on trying to learn node.js, and am playing around with the imap and mailparser sample code found here . 我正在尝试学习node.js,并在这里找到imap和mailparser示例代码 I installed both imap and mailparser according to the instructions in the readme documents found on their respective github pages, and everything installed fine without any errors. 我根据在各自的github页面上找到的自述文件中的说明安装了imapmailparser ,并且一切都安装良好,没有任何错误。 When attempting to run the sample code, I get the following error: 尝试运行示例代码时,出现以下错误:

Error: Cannot find module 'iconv'

After installing the modules, my project directory structure looks like this: 安装模块后,我的项目目录结构如下所示:

~/ProjectDir
    |
    -- node_modules
    |   |
    |   -- imap
    |   |   |
    |   |   -- LICENSE
    |   |   -- README.md
    |   |   -- imap.js
    |   |   -- package.json
    |   -- mailparser
    |   |   |
    |   |   -- lib
    |   |   |   |
    |   |   |   -- datetime.js
    |   |   |   -- mailparser.js
    |   |   |   -- streams.js
    |   |   -- node_modules
    |   |   |   |
    |   |   |   -- iconv
    |   |   |   |   ...
    |   |   |   -- mimelib
    |   |   |   |   ...
    |   |   -- test
    |   |   |   ...
    |   |   -- LICENSE
    |   |   -- README.md
    |   |   -- package.json
    |   |       ...
    |   -- config.json
    |   -- mailFether.js
    |   -- readme.md

So, based on some of the googling that I've done for this problem, I've noticed that this "Cannot find module" error seems to be a fairly common one, but I've been able to see a consistent solution to the problem. 因此,根据我为解决该问题所做的一些搜索,我注意到此“找不到模块”错误似乎是很常见的错误,但是我已经能够看到针对该问题的一致解决方案问题。

Is the problem here the nested node_modules directory in the mailparser folder? 这是mailparser文件夹中嵌套的node_modules目录的问题吗? Should the contents of that folder actually be in the node_modules folder at the root of the project? 该文件夹的内容是否应该真正位于项目根目录的node_modules文件夹中? Is this a project setup issue, or an environmental issue? 这是项目设置问题还是环境问题?

Just try to install the iconv module: npm install iconv - and take a look at the output of this command, iirc iconv builds a binary, this could fail under circumstances, then we should figure out why it's failing - but in this case one could only help if you provide the output of the install command. 只需尝试安装iconv模块: npm install iconv iconv-并查看此命令的输出,iirc iconv会生成一个二进制文件,这种情况在某些情况下可能会失败,然后我们应该弄清楚为什么它会失败-但在这种情况下,仅当您提供install命令的输出时才有帮助。

Is the problem here the nested node_modules directory in the mailparser folder? 这是mailparser文件夹中嵌套的node_modules目录的问题吗?

No, this is ok, this is how npm works. 不,没关系,这就是npm的工作方式。 All dependencies of a module are stored in a nested node_module folder. 模块的所有依赖项都存储在嵌套的node_module文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM