简体   繁体   中英

'Can't find module fs' when running casperjs on js file

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.

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

casperjs和phantomjs是全球安装的吗?

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 fs module defined in the package.json, or run npm uninstall fs

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