简体   繁体   English

如何在Heroku中运行节点控制的Phantomjs / Casperjs脚本

[英]How to run Node controlled Phantomjs/Casperjs script in Heroku

I've written a Casperjs script to do some scraping, however, after running into memory exhaustion issues , I've now written a node script to turn Phantom off and on via exec. 我已经编写了一个Casperjs脚本来进行一些抓取,但是,在遇到内存耗尽问题之后 ,我现在已经编写了一个节点脚本来通过exec打开和关闭Phantom。 I can run this with no issues locally, however when I deploy to heroku I get the following error 我可以在本地运行,没有任何问题,但是当我部署到heroku时,出现以下错误

Error: Command failed: casperjs turnitoffandon.js
ERROR: stderr was:/bin/sh 1: casperjs: not found

I used the nodejs buildpack and have Phantom and Casper defined in my dependencies. 我使用了nodejs buildpack,并在我的依赖项中定义了Phantom和Casper。 In the heroku bash, running phantomjs --version returns 2.1.1 and casperjs --version returns 1.1.4. 在heroku bash中,运行phantomjs --version返回2.1.1,而casperjs --version返回1.1.4。

Do I need to define where Casper is? 我需要定义Casper的位置吗? If so how? 如果可以,怎么办? I have set my PATH variable as /usr/local/bin:/usr/bin:/bin:/app/vendor/phantomjs/bin:/app/vendor/casperjs/bin:/node_module/casperjs/bin , like in this SO question 我已经将我的PATH变量设置为/usr/local/bin:/usr/bin:/bin:/app/vendor/phantomjs/bin:/app/vendor/casperjs/bin:/node_module/casperjs/bin ,就像这样所以问题

The issue actually had nothing to do with Heroku. 这个问题实际上与Heroku无关。 As noted in this SO answer , using exec and providing any environmental variables in the options parameter replaces the entire set of environment variables. 该SO答案所述 ,使用exec并在options参数中提供任何环境变量将替换整个环境变量集。 This includes the path, effectively overwriting any paths already specified to Heroku in the buildpack and npm modules. 这包括路径,有效覆盖了buildpack和npm模块中已经指定给Heroku的所有路径。

You can create a copy of process.env and pass that along in the parameters in addition to other environmental parameters needed to be passed. 您可以创建process.env的副本,并在需要传递的其他环境参数之外将其传递给参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM