plouc / mozaik

Mozaïk is a tool based on nodejs / react / redux / nivo / d3 to easily craft beautiful dashboards
http://mozaik.rocks
MIT License
3.61k stars 363 forks source link

startup error with yo-configured time widget #36

Closed mblakele closed 9 years ago

mblakele commented 9 years ago

Following the instructions at https://github.com/plouc/mozaik I used yo mozaik, which prompted me to select widgets. I selected the time widget, plus a few others. However node app.js produced an error:

module.js:322
    throw err;
          ^
Error: Cannot find module 'mozaik-ext-time/components/index'
    at Function.Module._resolveFilename (module.js:320:15)
    at Function.Module._load (module.js:262:25)
    at Module.require (module.js:349:17)
    at require (module.js:368:17)
    at Object.<anonymous> (/Users/mblakele/Source/mozaik-test/app.js:3:33)
    at Module._compile (module.js:444:26)
    at Object.Module._extensions..js (module.js:462:10)
    at Module.load (module.js:339:32)
    at Function.Module._load (module.js:294:12)
    at Function.Module.runMain (module.js:485:10)

The problem seems to be this line that yo mozaik added to my app.js:

mozaik.bus.registerApi('time',  require('mozaik-ext-time/client'));

However the time widget doesn't have a backend.

Workaround: comment out the line for time/client in app.js.

ThrowingSpoon commented 9 years ago

I called the 'time' component directly. In:

(mozaik project folder)/node_modules/mozaik-ext-time/client.js

I changed the single line of code from:

module.exports = require('./lib/client');

to:

module.exports = require('./lib/components/Clock.js');

This does however generate a warning:

Warning: Something is calling a React component directly. Use a factory or JSX instead. See: http://fb.me/react-legacyfactory

Although the clock widget does appear to be working fine, does anybody know of any issues that may arise from calling this component directly?

Liam.

plouc commented 9 years ago

@mblakele I have to fix the generator to only require extension's client if it's available.

plouc commented 9 years ago

@ThrowingSpoon how do you instantiate the clock component ? When you use mozaïk, the widget is instantiated using this code https://github.com/plouc/mozaik/blob/master/src/browser/components/Widget.jsx#L18 If you're curious, you can read more about this here https://gist.github.com/sebmarkbage/ae327f2eda03bf165261

plouc commented 9 years ago

@mblakele I fixed the issue with extra client declaration, see https://github.com/plouc/mozaik-generator/commit/6480b100e696f2b31793561764683ceef2541e90 Feel free to re-open this issue if it does not fix the problem. (You'll have to update the yeoman generator)