jedireza / hapi-react-views

:package: A hapi view engine for React components
MIT License
231 stars 33 forks source link

Internal implementation error #46

Closed ADumaine closed 8 years ago

ADumaine commented 8 years ago

I am in the process of updating a project from react 13 to 14 and hapi 11 along with updating to all the latest node modules in the project (based on dependencies). I've been able to sort out all the issues but am stuck on this one as it says it is an internal error. It seems to point to issue with rendering views by hapi-react-views but there is not enough info in the debug for me to figure it out. It appears to be an issue with an unexpected token <: but the project uses babel loader on all the jsx files. I have tried using the useNodeJsx:false in the manifest and that had no effect.

Is there some sort of compatibility issue with hapi-react-views and vision?

Here is the debug output. Any insight is appreciated.

Debug: internal, implementation, error
    SyntaxError: Unexpected token <: Unexpected token <
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at runtime (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi-react-views\index.js:24:25)
    at Object.renderer (C:\Data\captchatheprize.com\dev\gamewww\node_modules\vision\lib\manager.js:143:36)
    at internals.Manager._loadPartials.internals.Manager._loadHelpers.internals.Manager.render.internals.Manager._prepare.internals.Manager._prepareEngine.internals.Manager._prepareTemplates.callback._path.internals.Manager._path.internals.Manager._render.compiled.template [as _render] (C:\Data\captchatheprize.com\dev\gamewww\node_modules\vision\lib\manager.js:470:14)
    at Object.internals.Manager._loadPartials.internals.Manager._loadHelpers.internals.Manager.render.internals.Manager._prepare.internals.Manager._prepareEngine.internals.Manager._prepareTemplates.callback._path.internals.Manager._path.internals.Manager._render.internals.Manager._compile.internals.marshal.callback [as marshal] (C:\Data\captchatheprize.com\dev\gamewww\node_modules\vision\lib\manager.js:564:13)
    at internals.Response._prepare.internals.Response._processPrepare.internals.Response._marshal.next [as _marshal] (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\response.js:464:22)
    at C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\transmit.js:124:18
    at C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\transmit.js:508:20
    at done (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\node_modules\items\lib\index.js:63:25)
    at autoValue (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\transmit.js:479:20)
    at Object.exports.parallel (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\node_modules\items\lib\index.js:70:13)
    at Object.exports.send.internals.marshal.internals.fail.internals.transmit.internals.state.Items.parallel [as state] (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\transmit.js:501:11)
    at Object.exports.send.internals.marshal.internals.state [as marshal] (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\transmit.js:98:15)
    at Object.exports.send.callback [as send] (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\transmit.js:30:15)
    at transmit (C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\request.js:439:18)
    at C:\Data\captchatheprize.com\dev\gamewww\node_modules\hapi\lib\protect.js:52:16
jedireza commented 8 years ago

Thanks for creating an issue. From the README:

Note: As of hapi-react-views v4.x your project must register a transpiler such as babel or node-jsx. An alternative to this is to transpile ahead of time and save the result to file.

The error your're seeing is because untranspiled code is being parsed.

You'll need to register a transpiler at a top level of your app:

require('babel-core/register')({
    presets: ['react', 'es2015']
});
ADumaine commented 8 years ago

I thought I had that implemented but I found it was not done correctly. Since I started with aqua which uses glue I was able to add it to the index.js composeOptions rather than trying to get it to work in the manifest (kept asking for attributes).

Here is how I implemented it within the preRegister options.

var Glue = require('glue');
var Manifest = require('./manifest');

var composeOptions = {
    relativeTo: __dirname,
    preRegister: function(server, next){
        require('babel-core/register')({
         presets: ['react', 'es2015']
        });
         next();
    }
};

module.exports = Glue.compose.bind(Glue, Manifest.get('/'), composeOptions);

Pages are now rendering. Thanks!!

jedireza commented 8 years ago

Oh cool, thanks for sharing that. :+1: