PhantomJS错误:TypeError: undefined不是构造函数(求值'require('s
PhantomJS error: TypeError: undefined is not a constructor (evaluating 'require('system').create()')
更新::问题解决了,我能够将它隔离到我的JAVASCRIPT文件。
cap_screen.js
var page = require('webpage').create(); //Create a new instance of a web page
var system = require('system').create(); //Our script needs to require Phantom's Web Page module
page.onError = function(msg, trace) { //Our script needs to require Phantom's Web Page module
var msgStack = ['ERROR: ' + msg];
if (trace && trace.length) {
msg.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
});
}
console.error(msgStack.join(''n'));
};
//Now write core of screen cap script
//Remember: system.args[1] = "http://wwww.clowder.com" system.args[2] = "clowder-pic.png"
page.open(system.args[1], function(status) {
console.log('Status: ' + status);
page.render(system.args[2]); //this line captures the screen
phantom.exit();
});
我的问题是当提交URL时,弹出以下错误:
TypeError: undefined is not a constructor (evaluating 'require('system').create()')
phantomjs://code/cap_screen.js:10 in global code
这是我的代码:
entries_controller
def create
@entry = Entry.new(entry_params)
@entry.image = cap_screen
if @entry.save
redirect_to root_path
else
render('index')
end
end
private
PATH_TO_PHANTOM_SCRIPT = Rails.root.join('app', 'assets', 'javascripts', 'cap_screen.js')
def cap_screen
Dir.chdir(Rails.root.join('public', 'images'))
system "phantomjs #{PATH_TO_PHANTOM_SCRIPT} #{params['entry_url']} # {params['entry_url']}.png"
end
def entry_params
params.require(:entry).permit(:title, :url)
end
在我的cap_screen.js文件中,我的IDE给了我警告"未解决的变量或类型幻影"。
想法吗?
对于那些对TypeError: undefined is not a constructor
有问题的人,对于我的问题,我不小心写了一行:
var system = require('system').create();
当它应该是
var system = require('system')
如果它在Spec文件中,请确保在提供者类中有create()函数(在下面的示例中MockService需要该函数)。
{
provide: .....Service,
useClass: MockService
}
export class MockService {
create() {
// your code for test
}
constructor() { }
}
我有同样的错误,但对于不同的字符串函数。
TypeError: undefined不是构造函数(求值'inputValue.replace(/[^0-9a-zA-Z,]/g, ")')
我的修复是添加". tostring ()"之间的变量和"。替换"方法调用"。我把我的代码包含在下面以供进一步参考。
(function () {
'use strict';
angular
.module('mo.pages.global-search.directives')
.directive('extentionListValidate', restrictTextfieldToAlphaNumericList);
function restrictTextfieldToAlphaNumericList() {
return {
require: 'ngModel',
link: function (scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.push(function (inputValue) {
var transformedInput = inputValue ? inputValue.toString().replace(/[^0-9a-zA-Z,]/g, '') : null;
if (transformedInput != inputValue) {
modelCtrl.$setViewValue(transformedInput);
modelCtrl.$render();
}
return transformedInput;
});
}
};
}
})();
相关文章:
- 如果在代码末尾进行求值,jQuery-console.log将提供空数组
- HEAD中LINK和STYLE元素的求值顺序
- 聚合物绑定条件属性和求值属性
- javascript/jquery-避免重复对条件求值
- 为什么-0===0的求值结果为true
- 为什么下面给出的表达式在javascript中的求值结果为30
- 如何从不同范围外的元素属性中获取求值表达式
- myFunc=function(){}应该立即在Javascript中求值
- 针对常量求值的角度表达式
- AngularJS-在$event.stopPropagation之后停止ng-click表达式求值
- Javascript:附加字符串中的事件,闭包中的变量求值
- 如何使用Angular 1.5组件将属性求值为字符串,这是一个自定义函数
- AngularJS表达式未求值
- 为什么我的JS"如果“;语句的求值结果总是为false
- eval函数-求值顺序
- LESS 文件中的 JavaScript 求值错误
- 如何从传递给 CasperJS 中求值的函数调用另一个函数
- 如何控制 Angular 指令的求值顺序
- Angularjs 指令不求值 ~
- PhantomJS错误:TypeError: undefined不是构造函数(求值'require('s