简体   繁体   中英

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 . 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. 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? Should the contents of that folder actually be in the node_modules folder at the root of the project? 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.

Is the problem here the nested node_modules directory in the mailparser folder?

No, this is ok, this is how npm works. All dependencies of a module are stored in a nested node_module folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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