Node.js mailparser module error: Cannot find module 'iconv'

1,215 views
Skip to first unread message

Bob Yexley

unread,
May 21, 2012, 9:48:48 AM5/21/12
to nod...@googlegroups.com

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?

Environment: Ubuntu 12.04, Node.js v0.6.17, npm v1.1.21.

mscdex

unread,
May 21, 2012, 3:38:51 PM5/21/12
to nodejs
On May 21, 9:48 am, Bob Yexley <ryex...@gmail.com> wrote:
> 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?

When you did `npm install mailparser`, it should have shown the iconv
module being configured and compiled. Did you see anything like that?

Bob Yexley

unread,
May 21, 2012, 4:33:51 PM5/21/12
to nod...@googlegroups.com
Yeah I remember seeing that. I remember scrolling back through as much of the details of that stuff as I could, and didn't see anything that I recognized as errors or anything like that. Looked like it all installed without any problems.

Anton Podviaznikov

unread,
May 21, 2012, 9:17:44 PM5/21/12
to nod...@googlegroups.com
I was also using code from that gist - everything worked for me.

You can try this module: https://github.com/circuithub/mail-listener. It is based on that gist. Maybe it will work.

Are you on windows?

Bob Yexley

unread,
May 21, 2012, 10:55:09 PM5/21/12
to nod...@googlegroups.com
I tried it on Windows at first, but the mailparser module won't install on Windows...I think iconv depends on node-waf, which doesn't run on Windows. So I switched over and am running it on Ubuntu now. I'm going to try just moving mailparsers modules up two levels into the main node_modules folder and see if that does anything to help the situation. We'll see...I'm open to other ideas if anyone has any of course.

Todd Newman

unread,
Jan 28, 2014, 6:23:14 PM1/28/14
to nod...@googlegroups.com
I realize this is a year late and is probably too late to help Bob. But in
case others find it with a web search, maybe it will help them.

mailparser requires iconv-lite. Then it wraps a
require("iconv") in a try-catch block. So if that fails, it fall back to
using iconv-lite. But if your development environment catches exceptions
when they're thrown, it looks like it's failing because iconv is missing.

I'm really liking that npm packages have all the source code available for
debugging, unlike compiled libraries. It makes this stuff easier to figure
out.

Todd


Reply all
Reply to author
Forward
0 new messages