Skip to content
This repository has been archived by the owner on Jan 26, 2020. It is now read-only.

bundlerUrl: bundle.js: Uncaught SyntaxError: Unexpected token < #61

Closed
adamzasah opened this issue Jul 19, 2018 · 4 comments
Closed

bundlerUrl: bundle.js: Uncaught SyntaxError: Unexpected token < #61

adamzasah opened this issue Jul 19, 2018 · 4 comments

Comments

@adamzasah
Copy link

adamzasah commented Jul 19, 2018

I am running rogue.js version 0.6.10 and still getting this issue for bundle.js. Mentioned in #20.

I am also new to SSR and I don't know if I figured out what is the right purpose for this bundle. Should it be compiled client side (client.js) script for usage when continuing with an app on the browser side after initial server render?

razzle example uses some client.js script so I don't know, because when I build the app via @roguejs/cli the bundle.js contains ES5 version of server.js code, but that may be the error and because of it I got confused.

Thanks for answer.
Keep up the great work. Rogue.js will be awesome.

@alidcast
Copy link
Owner

alidcast commented Jul 19, 2018

Does the with-razzle example work for you? That's how I would recommend getting started as roguejs/cli is a work in progress. Partly due to time contraints and partly because I'm waiting for Parcel to be further along.

The bundleUrl indicates where your client bundle is located. It can either be a relative path (relative to public directory, e.g. bundle.js) or an absolute url path (like in razzle it's something like http:localhost:3000/client.js` since webpack is serving the assets)

And yes, you're correct, the client bundle is used after initial server render.

Rogue adds a script to the document that tells browser where to look for it: https://github.com/alidcastano/rogue.js/blob/master/packages/rogue-app/lib/server/toHtml.ts#L25

@adamzasah
Copy link
Author

adamzasah commented Jul 20, 2018

@alidcastano Thanks for the quick response.

The razzle one works for me, but I have tried zero config with @rogue/cli and only with App.js. That produced same Unexpected token < error with bundled script.

I have this server.js and I am running it with babel-node ./src/server.js via babel-cli package uncompiled and it does produce same error Unexpected token <.
.babelrc has just env and react presets, nothing else.

import Rogue from '@roguejs/app/server';
import http from 'http';
import App from './app/App';

const rogue = new Rogue(App, {});

const server = http.createServer(rogue.render);

server.listen(3000, error => {
    if (error) {
      console.log(error);
    }
  
    console.log('🚀 started');
  });

The App React component renders just plain 'Hello World' string.

Maybe I need newer node.js? I am running v8.6.0.

Probably I just go with razzle even though I wanted to set things up for myself manually first.

@alidcast
Copy link
Owner

The Unexpected token < can occur when there's an error pertaining to your client bundle, such as it not being found

bundleUrl needs to point to the compiled client bundle

so in your case, if you're in development, it'll be relative to wherever babel-node is compiling src/client.js to

let me know if you can get it to work, otherwise if you can make a tiny example I can check it out

@adamzasah
Copy link
Author

@alidcastano Thanks for the answer. Yeah, it was the problem with the wrong relative path to bundle. Now it works. Anyway, I am now using rattle, its zero config and its nice. ❤️ Thanks for help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants