Giter Club home page Giter Club logo

mobx-starter's Introduction

React + Mobx Quick Starter project

The goal of this project is to provide a starting base for an isomorphic (universal) mobx react project.

Features:

  • async/await support
  • Isomorphic
  • CSS and SCSS compilation
  • MongoDB user register/login/logout
  • Token based authentication
  • Decorators for easily accessing the state
  • Hot reloading and sourcemaps
  • Automatic restarts (when server code changes)

Preview

How to run

For development:

npm run dev

For production:

npm run prod

Requirements

Node 6+ or Node 4 with additional babel plugins
MongoDB server

Goals

  • Optimized for minimal bundle size.
  • Optimized for speed.
  • Using MobX, the easiest and insanely fast state manager.
  • Simple and minimal with routing, authentication, database and server-side rendering.
  • Good developer experience with hot-reloading and source-maps.

Benchmarks

gb -k=true -c 300 -n 10000 http://localhost:2000/page/about

This is GoHttpBench, Version 0.1.9, https://github.com/parkghost/gohttpbench
Author: Brandon Chen, Email: [email protected]
Licensed under the MIT license

...

Concurrency Level:      300
Time taken for tests:   15.34 seconds
Complete requests:      10000
Failed requests:        0
HTML transferred:       11190000 bytes
Requests per second:    651.80 [#/sec] (mean)
Time per request:       460.263 [ms] (mean)
Time per request:       1.534 [ms] (mean, across all concurrent requests)
HTML Transfer rate:     712.22 [Kbytes/sec] received

Connection Times (ms)
              min       mean[+/-sd]     median  max
Total:        166       1   149.29      412     1527

Tested on i7-6700K @ 4.00GHz 16GB RAM. Single node.js instance.

Adding database (mongodb) models

  1. Goto src/server/models
  2. Add [Name].js with your model in it

Adding stores

  1. Goto src/config/stores
  2. Add [Name].js (it's just a class, ex: Account.js)
  3. Update src/config/stores.js

Disabling server-side rendering

  1. Goto server/middleware/render.js
  2. Change const components = ... to const components = null

F.A.Q.

What are stores ?

State contains the state of your application (ex: list of your todos, UI state etc). Stores contain the methods that mutate that state (ex: adding a todo, fetching data). Technically our State object is also a store, but we make the differentiation so that our logic is easier to follow by using the same principes as redux (one big state object).

What is @inject() and @observer ?

The @inject decorator injects stores into your components. Additionally by adding @observer your components will efficiently auto update with any changes to your stores.

Example: If you display a messageCount from a Messages store and it gets updated, then all the visible components that display that messageCount will update themselves.

Does observing many components make my app slower?

No, it actually allows the rendering to be done more efficiently. So observe as many as you want !

My components are not updating!

Make sure you added the @observer decorator to your component.

My stateless component doesn't have access to the stores !

You cannot use decorators on stateless components. You should instead wrap your component like this:

const MyComponent = inject('myStore')(observer((props, context) => {
  return <p>{props.myStore.something} !</p>
}))

How do I execute async actions on the server and/or client ?

Add a static onEnter method to your component like this:

class MyComponent extends React.Component {
    static onEnter({ state, store }, params) {
        return store.myStore.browse()
    }
    // ...
}

The onEnter method is smart, it will be executed either on the server or on the browser depending on how you access the website.

It also passes all your stores and url params as arguments as a convenience.

How it works (server)

  1. index.js initializes the logger, generates a webpack bundle and runs the server

  2. The server runs a bunch of middleware:

    1. context.js creates your initial state based on your stores defined in src/client/stores.js
    2. authorize.js checks if you are logged in and have access to protected routes.
    3. render.js finally renders your components.
  3. server.js also imports the routes from server/routes where each route can use a database model defined in server/models. Just adding a model file there is enough, the models are initialized when they are used.

How it works (client)

  1. client.js initializes the stores, hot-reloading and other helpers.
  2. It hydrates the state we got from the server and renders pages/Index.js
  3. pages/Index.js is basically your entry point. What you do afterwards is up to you!

Useful links

MobX

Author

Ryan Megidov

https://github.com/nightwolfz/mobx-starter

mobx-starter's People

Contributors

aminetrabelsi avatar mjyoung avatar nightwolfz avatar xcodebuild avatar zorganovic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mobx-starter's Issues

HMR not working?

Hi there!

First of all, thanks for this starter kit. It looks great. I am having some issues getting hot module replacement to work, however.

My steps were:

1. git clone
2. npm install
3. npm run dev
4. change the HTML static content in About.js

[HMR] says it updated the modules but the browser doesn't show the DOM updated, and there's some warning about React-Router (don't know if relevant):
image

If I manually refresh with command + R then the view is properly updated.

Any thoughts?

registration and login fail

clone and npm installed with node version v6.2.1 aok
landing page works
attempting to register or login .... not so good.

mobx-starter git:(master) npm run dev

> [email protected] dev /Users/paul/projects/mobx-starter
> cross-env NODE_ENV=development node ./index.js

[Static] /build - /Users/paul/projects/mobx-starter/build
HTTP Server listening on port 2000
Webpack DEV Server running on port 2002
Mongodb started on port 27017
webpack built 39bb58bee961b7247e0a in 8309ms
Hash: 39bb58bee961b7247e0a
Version: webpack 2.1.0-beta.14
Time: 8309ms
     Asset     Size  Chunks             Chunk Names
 bundle.js  4.75 MB       0  [emitted]  bundle
bundle.css  5.82 kB       0  [emitted]  bundle
Child extract-text-webpack-plugin:

webpack: bundle is now VALID.
Fetching: api/todos
Unhandled rejection ReferenceError: username is not defined
    at /Users/paul/projects/mobx-starter/src/server/routes/account.js:176:82
    at boundThen (/Users/paul/projects/mobx-starter/src/client/components/Home.js:150:25)
    at /Users/paul/projects/mobx-starter/src/server/routes/account.js:172:12
    at Layer.handle [as handle_request] (/Users/paul/projects/mobx-starter/node_modules/express/lib/router/layer.js:95:5)


The accounts document IS being created in the db (password is NOT hashed which is not so great). I'm confused by the error as it references server/routes/account.js:176:82. The source file I have only has 74 lines in it so I have no idea where or what the actual problem is that causes the failure.

onEnter not called on client

From what I understood from the readme, onEnter should be isomorphic, but it doesn't seem to be called from the client. RRv4 doesn't call onEnter like v2.

Also, on the server side it seems that preload.js executes all of the onEnter methods.

Actions?

Hi,

I was just wondering if there was a specific reason why you arent using actions here?

Cheers,
Mike

Typescript

Hi,

Love this starter project, absolutely nails all the essentials in a modern SPA.

I am however a bit of a Typescript fan so would love to use TS on both the client and server. I dont suppose you know anyone that has had a go at converting this to use Typescript have you before I start?

Cheers,
Mike

Support for file.server.js and file.client.js

Quick question about a feature: Could there be any way of splitting components while still maintaining same aliases? Something like: MyComponent.server.js and MyComponent.client.js.

An import MyComponent from './MyComponent' would then load the respective code. I'm asking because some third party libraries throw DOM errors in SSR and I want to return empty divs in such cases.

This could also prove useful in stores. For example account.server.js does a database lookup while account.client.js does a fetch.

I know we can use if (process.env.BROWSER) but then we can no longer use es6 imports as they need to appear before any code (sometimes even importing a module crashes the server). To work around that we need manual require (...) hacks which results in very ugly code.

So I'm thinking maybe there can be some Webpack magic to accomplish this. In nodejs we can wrap require.extensions['js']. Any ideas? Thanks!

npm run prod - Unexpected token <

I saw this issue closed previously, but am experiencing it again.

node -v = v8.5.0
npm -v = 5.3.0
if you clone a fresh build of this repo and do npm i && npm run prod the build will not fail ( or indicate there was a compilation error however the browser doesn't have any css :( I'm still looking into why this is failing with a Uncaught SyntaxError: Unexpected token < in the browser console upon load, but any insight would be appreciated.

Thanks!

onEnter is only called on '/' path

Is this intentional? Is the idea that you should build any state in the initial page load? Or would you add an onEnter method to all your components and call browse() on any store data they require. Admittedly I'm still getting my head around how this works.

Logging the branches variable from render.js to console looks like it only ever matches on '/'.

can not run

I just git cloned this repo, and npm i, and npm run dev, then got this:
image
my node is v7.1.0, npm 3.10.9, during installation there is no error or warning.
I tried install a mongodb, still got this.

Hot Module Replacement not working for CSS changes.

First of all, love this starter pack!

I ran into a small issue -- in dev mode, HMR is working with changes to the JSX but not working with changes to the CSS files. I believe this has to do with the fact that we are using extract-text-webpack-plugin in dev.

Taken from:
https://github.com/webpack/extract-text-webpack-plugin

Caveats:

Additional HTTP request
Longer compilation time
More complex configuration
No runtime public path modification
No Hot Module Replacement

on branch next menu is not refreshed

On branch next
Please find below the scenario
1- register test/test
2- logout
3- click on login then type test/test and press the button
the menu is not refreshed : login still visible
press F5 login becomes logout

Isomorphic onEnter fix for next-2

This is how I fixed onEnter on next-2 branch. I'm using these params for onEnter: onEnter(state, store, match).

Index:

class Index extends React.Component {
  render() {
    const { state, store } = this.props;
    return (
      <Provider {...this.props} >
        <div>
          <Menu />
          <Switch>
            {routes.map((route, i) => (
              <Route
                key={i}
                exact={route.exact}
                path={route.path}
                // We are overriding render rather than providing a component.
                // This also allows us to perform pre-render actions such as authentication.
                render={({ match }) => {
                  // We can maybe turn the isLoggedIn into a computed property
                  // I'm not sure if this would cause unwanted re-renders when Index is observable
                  if (route.protected && !store.account.isLoggedIn()) {
                    // I haven't really tested this part on server-side...
                    return <Redirect to='/login' />;
                  }

                  return <RouteWrapper component={route.component} match={match} state={state} store={store} />;
                }} />
            ))}
            <Route component={NotFound} />
          </Switch>
        </div>
      </Provider>
    )
  }
}

Implementation of RouteWrapper:

class RouteWrapper extends React.Component {
  // This works because componendDidMount is not called server-side
  componentDidMount() {
    const { component: Component, state, store, match } = this.props;
    if (Component.onEnter) {
      // These 3 objects passed to onEnter should cover 99% of use cases
      // if we need something else we can use componentDidMount or modify this code
      Component.onEnter(state, store, match);
    }
  }

  render() {
    const { component: Component, state, store, match } = this.props;
    // We get state, store, and match for free without any @inject or withRouter
    return <Component state={state} store={store} match={match} />;
  }
}

Somewhere in render.js

const promises = branches.map(({ route, match }) => {
  // This also seems like a good place to check route.protected
  // to send a true http redirect
  return route.component.onEnter
    ? route.component.onEnter(ctx.context.state, ctx.context.store, match)
    : Promise.resolve(null)
})

Note: exact={route.exact} implies that by default this property is false. If we want a default true we can do something like exact={!('exact' in route) || route.exact}

spawn cmd ENOENT

Hi how i can modify this error

[email protected] dev C:\Users\l\Desktop\mobx-starter
cross-env NODE_ENV=development nodemon ./index.js

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Users\l\AppData\Roam ing\npm\node_modules\npm\bin\npm-cli.js" "run" "dev"
npm ERR! node v6.11.0
npm ERR! npm v4.1.2
npm ERR! file cmd
npm ERR! path cmd
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn cmd
npm ERR! [email protected] dev: cross-env NODE_ENV=development nodemon ./index .js
npm ERR! spawn cmd ENOENT
npm ERR!
npm ERR! Failed at the [email protected] dev script 'cross-env NODE_ENV=develop ment nodemon ./index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mobx-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! cross-env NODE_ENV=development nodemon ./index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs mobx-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls mobx-starter
npm ERR! There is likely additional logging output above.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Users\l\AppData\Roam ing\npm\node_modules\npm\bin\npm-cli.js" "run" "dev"
npm ERR! node v6.11.0
npm ERR! npm v4.1.2
npm ERR! code ELIFECYCLE

npm ERR! [email protected] dev: cross-env NODE_ENV=development nodemon ./index .js
npm ERR! Exit status -4058
npm ERR!
npm ERR! Failed at the [email protected] dev script 'cross-env NODE_ENV=develop ment nodemon ./index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mobx-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! cross-env NODE_ENV=development nodemon ./index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs mobx-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls mobx-starter
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to in stall?
npm WARN Local package.json exists, but node_modules missing, did you mean to in stall?

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\l\Desktop\mobx-starter\npm-debug.log

npm run prod - Unexpected token <

Hi,

when I try to run "npm run prod", the app partly renders and shows the next error:
"Uncaught SyntaxError: Unexpected token <"
Im using node v6.9.1 and local mongo is running.
Everything seems to work ok when using the dev script.

One more question is how should i host this on heroku? I just upload the whole project without changing anything?

Thanks in advance.

update README.md

Hi,

I think that the documetation needs update :

  • @connect is no more used
  • server.SSR disappeared from the config file
  • catcher.js no more used (why?)
    by the way enabling catcher prevents the app from starting.
    I noticed also that if we try to register a user with special characters in his username the rendered validation message is "Internal Server Error" and not the more precise one written in server/routes/account.js line 52

graphql server

Hello there,
I integrated graphql server and enabled graphiql
Q: How to render graphiql query page instead of NotFound page when entering localhost:2000/graphql?
Has anyone else integrate it before?

Thanks

app fails when todo is added

i'm using a windows 10 machine and experiencing app failure when a todo is added.

here is the console:
Asset Size Chunks Chunk Names
bundle.js 2.58 MB 0 [emitted] [big] bundle
bundle.css 5.89 kB 0 [emitted] bundle
bundle.js.map 2.81 MB 0 [emitted] bundle
bundle.css.map 16.5 kB 0 [emitted] bundle
webpack: Compiled successfully.
ERR
ERR ValidationError: createdBy: Cast to ObjectID failed for value "{}" at path "createdBy"
at new ValidationError (C:\Users\user\mobx1\node_modules\mongoose\lib\error\validation.js:28:11)
at model.Document.invalidate (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:1612:32)
at model.Document.set (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:761:10)
at model._handleIndex (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:594:14)
at model.Document.set (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:554:24)
at model.Document (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:73:12)
at model.Model (C:\Users\user\mobx1\node_modules\mongoose\lib\model.js:47:12)
at new model (C:\Users\user\mobx1\node_modules\mongoose\lib\model.js:3698:13)
at C:/Users/user/mobx1/server/routes/todos.js:22:19
at new Promise ()
at addTodos (C:/Users/user/mobx1/server/routes/todos.js:17:8)
at dispatch (C:\Users\user\mobx1\node_modules\koa-router\node_modules\koa-compose\index.js:44:32)
at next (C:\Users\user\mobx1\node_modules\koa-router\node_modules\koa-compose\index.js:45:18)
at C:\Users\user\mobx1\node_modules\koa-router\lib\router.js:346:16
at dispatch (C:\Users\user\mobx1\node_modules\koa-router\node_modules\koa-compose\index.js:44:32)
at C:\Users\user\mobx1\node_modules\koa-router\node_modules\koa-compose\index.js:36:12

(NOTE: i registered and logged in first)

console message (from the code below) shows ctx.account.id is undefined and account.token is ok.

`export async function login(ctx) {
const { username, password } = ctx.request.fields
const account = await Account.findOne({
username,
password: sha512(password, { salt: username })
})
if (!account) throw new Exception('Wrong credentials')

account.token = createAuthToken(account._id)
await account.save()

ctx.cookies.set('token', account.token)
ctx.body = account.toJSON()
console.info('Logged-in context '+ ctx.account.id + ' ' + account.token)
}`

``

Error: webpack.base.js: The resolved config file doesn't contain a resolve configuration

I can't start mobx-starter application on Windows 7. This is output of npm run dev command on clean mobx-starter installation:

> npm run dev

> [email protected] dev c:\OpenServer\domains\ads\mobx-starter
> cross-env NODE_ENV=development nodemon ./index.js

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: c:\OpenServer\domains\ads\mobx-starter\src\server/**/* src/shared
[nodemon] starting `node ./index.js`
C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-core\lib\transformation\file\index.js:578
        throw err;
        ^

Error: c:/OpenServer/domains/ads/mobx-starter/core/webpack/webpack.base.js: The resolved config file doesn't contain a resolve configuration
    at PluginPass.CallExpression (c:\OpenServer\domains\ads\mobx-starter\node_modules\babel-plugin-webpack-alias\build\index.js:48:27)
    at newFn (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\visitors.js:276:21)
    at NodePath._call (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\path\context.js:76:18)
    at NodePath.call (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\path\context.js:48:17)
    at NodePath.visit (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\path\context.js:105:12)
    at TraversalContext.visitQueue (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\context.js:150:16)
    at TraversalContext.visitSingle (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\context.js:108:19)
    at TraversalContext.visit (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\context.js:192:19)
    at Function.traverse.node (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\index.js:114:17)
    at NodePath.visit (C:\OpenServer\domains\ads\mobx-starter\node_modules\babel-traverse\lib\path\context.js:115:19)
 [nodemon] app crashed - waiting for file changes before starting...

npm -v
3.8.6
node -v
v6.1.0
os
Windows 7 64bit

Webpack not working.

Got this error in console.

logger:error WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module.loaders[0] has an unknown property 'babelrc'. These properties are valid:
   object { enforce?, exclude?, include?, issuer?, loader?, loaders?, oneOf?, options?, parser?, query?, resource?, rules?, test?, use? }
 - configuration.resolve.extensions[0] should not be empty.

About.js component connected

The About component is decorated with the @connect decorator, but it has no dynamic content in it.
Nothing changes so no reason to have it decorated. Did i miss something?

externals?

Hey,

I would like to get that 500kb prod-bundle down a little. Im thinking externalizing React and Lodash etc, how would I go about that you think?

Mike

Question: Working with params

Hey
I'm using your starter to dig deeper in mobx and I have a question regarding route params. What I wanna achieve is that some of my routes are prefixed by a city, for example:

/berlin/events

The available cities come from an api request and I need the complete city list a lot of the times, hence why I don't wanna introduce a new request to ask if the specific city exists.

The result looks like this:

{
  cities: [
  {
    id: 1,
    name: "Berlin",
    country: "Germany",
    default: 1,
    slug: "berlin"
  },
  {
    id: 2,
    name: "Hamburg",
    country: "Germany",
    default: 0,
    slug: "hamburg"
  }
  ]
}

What I set up is this route:

            <Route path=":city" getComponent={requireAsync('Cities/Main')}>
                <IndexRoute getComponent={requireAsync('Cities/Landingpage')} />
            </Route>

and the fetchData method as well as componendDidMount just like you did in your example for fetching todos. Works fine, all the cities are fetched.

What I want to do now is call and action where it filters the items by slug and sets it as the "active" city. I just don't know where I would call the action ideally.

I hope you understand what I'm trying to achieve

Sth must be wrong

Hi

After running the project, the home page looks not as pretty as the preview.png

mobx-starter

My console looks this way
app:warn Mobx observer: Using observer to inject stores is deprecated since 4.0. Use @inject("store1", "store2") @observer ComponentClass or inject("store1", "store2")(observer(componentClass)) instead of @observer(["store1", "store2"]) ComponentClass +0ms
koa deprecated Support for generators will been removed in v3. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/tree/v2.x#old-signature-middleware-v1x src/server/server.js:57:5
app:static /home/vagrant/projects/mobx-starter/build +113ms
koa deprecated Support for generators will been removed in v3. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/tree/v2.x#old-signature-middleware-v1x src/server/server.js:73:9
app:start Listening on port 2000 +34ms
webpack:compiler Running on port 2002 +2ms
Asset Size Chunks Chunk Names
bundle.js 2.21 MB 0 [emitted] bundle
bundle.css 5.86 kB 0 [emitted] bundle
bundle.js.map 2.5 MB 0 [emitted] bundle
bundle.css.map 17 kB 0 [emitted] bundle
webpack: bundle is now VALID.

Getting params

Hi
I'm missing something about how to get the URL params
Supose we have a route in App.js
<Match pattern="/page/applicants/enroll/:id" component={EnrollApplicant}/>
In preload.js we put
pattern: '/page/applicants/enroll/:id', execute: EnrollApplicant.onEnter

But when I call console.log(params) in onEnter I have undefined

I'm suspecting refactoring fetchData to onEnter broke this !

Websocket error thrown from react-devtools

Hi,

I'm seeing an error thrown by React Devtools in the Chrome console on both the master and next-WIP branches when running npm run dev:

WebSocket connection to 'ws://localhost:8097/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I've confirmed this isn't occurring in other React projects I'm working on, just this one that I cloned from the mobx-starter repo. My version of Chrome was updated today, and my version of react-devtools was reinstalled today as well. Any ideas why this may be happening?

image

Thanks for the work you've done here!

branch next won't run

Hi

After pulling next, npm install and npm run dev I got this error
vagrant@dev-ts:~/projects/mobx-starter$ npm run dev
[email protected] dev /home/vagrant/projects/mobx-starter
cross-env NODE_ENV=development nodemon ./index.js
[nodemon] 1.11.0
[nodemon] to restart at any time, enter rs
[nodemon] watching: /home/vagrant/projects/mobx-starter/core//* src/client/stores.js src/client/preload.js /home/vagrant/projects/mobx-starter/server//*
[nodemon] starting node ./index.js
/home/vagrant/projects/mobx-starter/node_modules/koa-mount/index.js:48
return async function (ctx, upstream){
^^^^^^^^
SyntaxError: Unexpected token function
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Module._extensions..js (module.js:579:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/vagrant/projects/mobx-starter/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/home/vagrant/projects/mobx-starter/server/server.js:5:1)
[nodemon] app crashed - waiting for file changes before starting...

SyntaxError: Unexpected token function

Hello,

I downloaded and built the package but encountered this error.


harfus-MacBook-Pro-2:mobx-starter harfuab$ node index.js --dev
INF Running on port 2002
/Users/harfuab/dev/mobx/support-service/mobx-starter/node_modules/koa-mount/index.js:48
return async function (ctx, upstream){
^^^^^^^^
SyntaxError: Unexpected token function
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Module._extensions..js (module.js:579:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/harfuab/dev/mobx/support-service/mobx-starter/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/Users/harfuab/dev/mobx/support-service/mobx-starter/server/server.js:18:17)
at Module._compile (module.js:570:32)
at loader (/Users/harfuab/dev/mobx/support-service/mobx-starter/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/harfuab/dev/mobx/support-service/mobx-starter/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Asset Size Chunks Chunk Names
bundle.js 2.58 MB 0 [emitted] [big] bundle
bundle.css 5.89 kB 0 [emitted] bundle
bundle.js.map 2.81 MB 0 [emitted] bundle
bundle.css.map 16.5 kB 0 [emitted] bundle
webpack: Compiled successfully.


If I browse to http://localhost:2002, I got

Cannot GET /

I appreciate if you provide some pointers.

Thanks

SyntaxError: unexpected token

Newb here looking for starters and I ran into a problem. I cloned, then npm install, then npm run dev as suggested and I get:

mobx-starter (master)$ npm run dev

> [email protected] dev /home/gb/tmp/mobx-starter
> cross-env NODE_ENV=development node ./index.js

/home/gb/tmp/mobx-starter/src/server/routes/account.js:145
        const { session } = req;
              ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at loader (/home/gb/tmp/mobx-starter/node_modules/babel-register/lib/node.js:158:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/gb/tmp/mobx-starter/node_modules/babel-register/lib/node.js:168:7)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/gb/tmp/mobx-starter/src/server/index.js:133:17)
    at Module._compile (module.js:410:26)
    at loader (/home/gb/tmp/mobx-starter/node_modules/babel-register/lib/node.js:158:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/gb/tmp/mobx-starter/node_modules/babel-register/lib/node.js:168:7)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/gb/tmp/mobx-starter/index.js:12:1)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)

npm ERR! Linux 4.4.0-28-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: `cross-env NODE_ENV=development node ./index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'cross-env NODE_ENV=development node ./index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mobx-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cross-env NODE_ENV=development node ./index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs mobx-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls mobx-starter
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/gb/tmp/mobx-starter/npm-debug.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.