jimjampez
jimjampez

Reputation: 1846

Cannot require a React.js component

I am trying to import a React.js component called 'fixed-data-table' and it's having problem on the line:

var FixedDataTable = require('fixed-data-table');

It throws the following error:

pez@pezbox:~/projects/react-server-example$ node server.js 
/home/pez/projects/react-server-example/node_modules/fixed-data-table/internal/ImmutableValue.js:65
      Object.assign(destination, propertyObjects[i]);
             ^
TypeError: undefined is not a function
    at Function.ImmutableValue.mergeAllPropertiesInto (/home/pez/projects/react-server-example/node_modules/fixed-data-table/internal/ImmutableValue.js:65:14)
    at new ImmutableObject (/home/pez/projects/react-server-example/node_modules/fixed-data-table/internal/ImmutableObject.js:50:20)
    at Object.<anonymous> (/home/pez/projects/react-server-example/node_modules/fixed-data-table/internal/FixedDataTableCell.react.js:22:21)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/pez/projects/react-server-example/node_modules/fixed-data-table/internal/FixedDataTableCellGroup.react.js:19:26)

I installed the depedencies using

sudo npm install

A strange thing is that it doesn't work if exclude sudo due to access permissions.

Any pointers with what's going wrong?

Upvotes: 0

Views: 831

Answers (1)

Ben
Ben

Reputation: 5412

You need to import object-assign.

Here's your error

Object.assign(destination, propertyObjects[i]);
       ^
TypeError: undefined is not a function

You can import object-assign like this:

/** @jsx React.DOM */
var assign = require('object-assign');

First, you probably want to install it using npm install. Here is the package.json that I use. Notice object-assign.

{
  "name": "gae-react-flux-todos",
  "version": "0.0.1",
  "description": "A simple TODOS app in React and Flux, built on top of Google App Engine",
  "author": "Ben Grunfeld",
  "repository": "https://github.com/bengrunfeld/gae-react-flux-todos",
  "readme": "https://github.com/bengrunfeld/gae-react-flux-todos/blob/master/README.md",
  "license": "Apache 2",
  "devDependencies": {
    "gulp": "^3.8.11",
    "gulp-browserify": "^0.5.0",
    "gulp-clean": "^0.3.1",
    "gulp-concat": "^2.2.0",
    "gulp-react": "^2.0.0",
    "gulp-replace": "^0.5.3",
    "browserify": "^9.0.3",
    "react": "^0.12.2",
    "reactify": "^0.13.1",
    "es6-promise": "^1.0.0",
    "flux": "^2.0.1",
    "object-assign": "^1.0.0",
    "jest-cli": "^0.4.0",
    "react-tools": "^0.12.0",
    "classnames": "1.2.0"
  }
}

Upvotes: 1

Related Questions