'Can't find module fs' when running ca

2019-05-29 08:17发布

I am trying to run CasperJS on a javascript file that I have, and when I run

> casperjs index.js 

it says

'CasperError: Cant find module fs'. 

The first line of index.js is

var fs = require('fs');

I have node, casperjs, and phantomjs installed, why can't it find fs? If I am correct, fs is Node's file system?

UPDATE: I added nodejs to my $PATH, but still no luck.

3条回答
We Are One
2楼-- · 2019-05-29 08:57

CasperJS is depending on PhantomJS, which have a built-in fs module. In Casper script, you are only able to use the phantomjs built-in fs module. See http://phantomjs.org/api/fs/

To solve the problem you describe, you will need to make sure there is no fsmodule defined in the package.json, or run npm uninstall fs

查看更多
孤傲高冷的网名
3楼-- · 2019-05-29 09:02

Are casperjs and phantomjs installed globally ?

查看更多
聊天终结者
4楼-- · 2019-05-29 09:09

Did you install the PhantomJS/CasperJS modules as well as the node fs module in your project? They don't seem to mix very well.

I ran into an issue where installed all of these modules and I was getting the same error message you mentioned above.

CasperError: Can't find module fs

Once I uninstalled the node 'fs' module, everything worked fine.

npm uninstall fs
查看更多
登录 后发表回答