每当我执行我的程序时,我都会收到以下TypeError
:
/home/Node-Project/node_modules/sentiment/lib/index.js:31
afinn = Object.assign(afinn, inject);
^
TypeError: Object function Object() { [native code] } has no method 'assign'
at module.exports (/home/Node-Project/node_modules/sentiment/lib/index.js:31:24)
at EventEmitter.<anonymous> (/home/Node-Project/twit4.js:17:9)
at EventEmitter.emit (events.js:95:17)
at EventEmitter.processTweet (/home/Node-Project/node_modules/ntwitter/lib/twitter.js:242:14)
at EventEmitter.emit (events.js:95:17)
at EventEmitter.receive (/home/Node-Project/node_modules/ntwitter/lib/parser.js:44:12)
at IncomingMessage.<anonymous> (/home/Node-Project/node_modules/ntwitter/lib/twitter.js:258:16)
at IncomingMessage.emit (events.js:95:17)
at IncomingMessage.<anonymous> (_stream_readable.js:765:14)
at IncomingMessage.emit (events.js:92:17)
我搜索了但我无法理解这个错误。
我是否必须安装特殊模块?
我是否需要更新Node或npm?
我的程序中是否有错误?
这是我的计划:
var twitter = require('ntwitter');
var credentials = require('./credentials3.js');
var sentiment = require ('sentiment');
var twit = new twitter({
consumer_key: credentials.consumer_key,
consumer_secret: credentials.consumer_secret,
access_token_key: credentials.access_token_key,
access_token_secret: credentials.access_token_secret
});
twit.stream('statuses/filter',{ 'locations':'loc'},
function(stream) {
stream.on('data', function(tweet) {
var twitterSentiment, geoColor;
sentiment(tweet.text, function (err, result) {
twitterSentiment = result;
if (result == 0) {
geoColor = '#B5B5B5';
} else if (result < 0) {
geoColor = '#FC0828';
} else {
geoColor = '#00DE1E';
} console.log(result);
});
});
});
有人可以解释一下吗?
答案 0 :(得分:8)
只有Node.js v4及更高版本内置了Object.assign
。
如果您使用的是旧版本的Node,则可以使用object.assign之类的polyfill。
答案 1 :(得分:1)
在Cordova项目中出现此类错误,添加此代码已解决了我的问题;
$start = $_POST['date1'];
$end = $_POST['date2'];
$query = "select * from table where date between '" . $end . "' and '" . $start . "'";
$stmt = $pdo->prepare($query);
$stmt->execute();
$data = array();
for ($i = 0; $i < 24; $i++){
$data[] = 0;
}
while($row = $stmt->fetch()){
$data[$row['horas']] = ((int)$row['pot']);
}
$post_data = json_encode($data);
echo $post_data;
}
来源:https://github.com/auth0/auth0-cordova/issues/46#issuecomment-311923820
答案 2 :(得分:0)
可能是我来不及了。我遇到了同样的问题,并在下面进行排序。从nodejs.org网站下载并安装最新版本的节点。参考视频https://docs.npmjs.com/getting-started/installing-node 并检查节点版本(节点-v),希望它应该是v6 +。希望它能解决你的问题。