5

Whenever I execute my program, I receive the following 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)

I searched but I am unable to understand this error.

Do I have to install a special module?

Do I have to update Node or npm?

Is there an error in my program?

Here is my program:

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);              
            });

        });
    });

Can someone please shed some light?

1
  • 3
    "Do I have to update Node" Most likely. Which version do you use? Have a look at node.green to see if your version supports Object.assign. Commented Nov 8, 2016 at 1:48

3 Answers 3

9

Only Node.js v4 and above has Object.assign built in.

If you're using an older version of Node, you can use a polyfill like object.assign.

Sign up to request clarification or add additional context in comments.

1 Comment

Better to just update to a more modern version of node.js.
4

Getting this kind of error in Cordova project, adding this code has fixed my problem;

if (typeof Object.assign != 'function') {
    Object.assign = function (target, varArgs) {
        'use strict';
        if (target == null) {
            throw new TypeError('Cannot convert undefined or null to object');
        }
        var to = Object(target);
        for (var index = 1; index < arguments.length; index++) {
            var nextSource = arguments[index];

            if (nextSource != null) {
                for (var nextKey in nextSource) {
                    if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
                        to[nextKey] = nextSource[nextKey];
                    }
                }
            }
         }
         return to;
    };
}

source: https://github.com/auth0/auth0-cordova/issues/46#issuecomment-311923820

Comments

0

May be I am too late. I have faced the same issue and sort it out like below. Download and install the latest version of the node from nodejs.org website. refer the video https://docs.npmjs.com/getting-started/installing-node and check node version (node -v), hope it should be v6+. Hope it resolves your issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.