Please help: Error: Cannot find module 'xls-to-json'

1,132 views
Skip to first unread message

HansPeterSloot

unread,
Aug 29, 2014, 2:02:43 PM8/29/14
to nod...@googlegroups.com
Hello,

I have installed xls-to-json but it does not seem to work.

How can I fix this?

Regards HansP

C:\Program Files\nodejs>npm install xls-to-json
xls-t...@0.3.1 node_modules\xls-to-json
├── c...@0.3.7
└── xl...@0.7.0 (comm...@2.3.0, c...@0.10.1, code...@1.3.4, s...@0.8.2)

C:\Program Files\nodejs>node c:\cygwin64\home\nl19856\xls2json.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'xls-to-json'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (c:\cygwin64\home\nl19856\xls2json.js:1:75)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

q2dg2b

unread,
Aug 29, 2014, 8:24:03 PM8/29/14
to nod...@googlegroups.com
I think you must run npm install inside c:\cygwin64\home\nl19856\

HansPeterSloot

unread,
Aug 30, 2014, 4:43:00 AM8/30/14
to nod...@googlegroups.com
BTW
this is the failing line:

node_xj = require("xls-to-json");

Op vrijdag 29 augustus 2014 20:02:43 UTC+2 schreef HansPeterSloot:

Tadeu Zagallo

unread,
Aug 30, 2014, 5:09:46 PM8/30/14
to nod...@googlegroups.com
I think the module should be installed on the same folder as your application.


Try moving the `node_modules` folder to `c:\cygwin64\home\nl19856\`

[]s


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/9fffa9f3-c96f-4ece-9239-2f65d8793707%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adrian Lynch

unread,
Aug 30, 2014, 5:10:06 PM8/30/14
to nod...@googlegroups.com
Show us your code and your directory structure for your project.

A


HansPeterSloot

unread,
Sep 1, 2014, 12:51:13 AM9/1/14
to nod...@googlegroups.com
The code:

  node_xj = require("xls-to-json");
  node_xj({
    input: "MSR5060S.xls",
    output: "MSR5060S.json"
  }, function(err, result) {
    if(err) {
      console.error(err);
    } else {
      console.log(result);
    }
  });

This is the entire project ;-)

Op zaterdag 30 augustus 2014 23:10:06 UTC+2 schreef Adrian Lynch:

klrumpf

unread,
Sep 2, 2014, 12:39:18 PM9/2/14
to nod...@googlegroups.com
perhaps also look at this, using it in production

https://github.com/SheetJS/js-xls

only thing one has to look out for is "numbers" that should be text formatted in the xls but get converted into scientific format. the work is to read the text data directly from the loade3d sheet data in these cases. Not a defect of the lib but rather of excel    

HansPeterSloot

unread,
Sep 2, 2014, 2:38:33 PM9/2/14
to nod...@googlegroups.com
When I put the code in the same directory as the node executable the error disappeared.

But I consider that  more or less 'dirty'.
How can I separate the code from the executables?

Op zaterdag 30 augustus 2014 23:09:46 UTC+2 schreef Tadeu Zagallo:

q2dg2b

unread,
Sep 2, 2014, 4:45:41 PM9/2/14
to nod...@googlegroups.com

Tadeu Zagallo

unread,
Sep 3, 2014, 10:40:51 AM9/3/14
to nod...@googlegroups.com
The  issue is not with `node` executable path, the problem is that you installed the module on the same folder as the executable. The modules should be installed on the root folder of your project.

Your project structure should be something like that:
.
├── index.js
└── node_modules
    └── xls-to-json
        ├── README.md
        ├── index.js
        ├── libs
        ├── node_modules
        ├── package.json
        ├── sample
        └── test

Ryan Schmidt

unread,
Sep 3, 2014, 3:01:21 PM9/3/14
to nod...@googlegroups.com
On Sep 2, 2014, at 1:38 PM, HansPeterSloot wrote:
> Op zaterdag 30 augustus 2014 23:09:46 UTC+2 schreef Tadeu Zagallo:
>> I think the module should be installed on the same folder as your application.
>

> When I put the code in the same directory as the node executable the error disappeared.
>
> But I consider that more or less 'dirty'.
> How can I separate the code from the executables?

You don't need to put your JavaScript file in the same directory as the node executable. Rather, you need to put the node_modules folder in the same directory as your JavaScript file. And this is accomplished by running the "npm install ..." command in the same directory as your JavaScript file. Each node project gets its own node_modules folder containing only the modules it asks for.

// ravi

unread,
Sep 3, 2014, 3:01:28 PM9/3/14
to nod...@googlegroups.com
On Sep 2, 2014, at 2:38 PM, HansPeterSloot <hanspet...@gmail.com> wrote:
> When I put the code in the same directory as the node executable the error disappeared.
>
> But I consider that more or less 'dirty'.
> How can I separate the code from the executables?
>

Not sure how/whether it works on Windows, but you may be able to achieve the separation above using NODE_PATH. See http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders.

—ravi

Adrian Lynch

unread,
Sep 3, 2014, 3:01:40 PM9/3/14
to nod...@googlegroups.com
On my mac, I have the following:

test
test/test.js
test/node_modules <--<< Created after running 'npm install xls-to-json'
data.xls
data.json <--<< Created after running 'node test.js'

Here's the script, copied from what you have:

var node_xj = require("xls-to-json");

node_xj(
{
input: "data.xls",
output: "data.json"
}, function(err, result) {
if(err) {
console.error(err);
} else {
console.log(result);
}
}
);

So it all looks to be working.

Start again.

Create a new folder, go into it. Run 'npm install xls-to-json'. Place your code in a file in the new folder. Run it with 'node your-script.js'.

What happens?

A



HansPeterSloot

unread,
Sep 4, 2014, 4:19:40 PM9/4/14
to nod...@googlegroups.com
It works !
Thanks to all who helped.



Op vrijdag 29 augustus 2014 20:02:43 UTC+2 schreef HansPeterSloot:
Hello,
Reply all
Reply to author
Forward
0 new messages