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

柔情痞子 提交于 2019-12-07 23:19:04

问题


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.


回答1:


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



回答2:


Are casperjs and phantomjs installed globally ?




回答3:


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



来源:https://stackoverflow.com/questions/39641513/cant-find-module-fs-when-running-casperjs-on-js-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!