leebenson / reactql

Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
https://reactql.org
MIT License
1.82k stars 173 forks source link

ReactQL3.0 entry acts funny trying to start server #169

Closed reduxdj closed 5 years ago

reduxdj commented 5 years ago

This is real weird one, I've upgrading my webpack to version 4 on my project based on reactql 3.0, and I'm hitting a snag where I can't pump in dynamic values of the manifest, and start the server. When I go to start the server after a build, the server complains about calling map on Object.values.

Here's the value of my manifest

{ 'browser.css': 'assets/css/style.css',
  'browser.js': 'browser.js'
}

Here's what I have:

import path from 'path'
import {readFileSync} from 'fs'
import PATHS from 'config/paths'
import {logServerStarted} from 'kit/lib/console'
import server, {createReactHandler, staticMiddleware} from './server'

const [manifest] = ['manifest']
  .map((name) => JSON.parse(readFileSync(path.resolve(PATHS.dist, `${name}.json`), 'utf8')))

console.log(manifest)
// Get manifest values
const css = manifest['browser.css']
const scripts = Object.values(manifest).map((item) => item.match('.js'))

// Spawn the development server.
// Runs inside an immediate `async` block, to await listening on ports
(async () => {
  const {app, router, listen} = server

  // Connect the production routes to the server
  router.get('/*', createReactHandler(css, scripts))
  app
    .use(staticMiddleware())
    .use(router.routes())
    .use(router.allowedMethods())

  // Spawn the server
  listen()

  // Log to the terminal that we're ready for action
  logServerStarted({
    type: 'server'
  })
})()

While the app builds starting the server gives me a peculiar error...


`},function(e,t,a){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BlogArticleInfo=t.CoverImage=t.PublishNote=t.BlogArticleItem=t.BlogArticlesContainer=void 0;var n,o=a(3),r=(n=o)&&n.__esModule?n:{default:n},i=a(12);t.BlogArticlesContainer=r.default.div.withConfig({displayName:"BlogArticlesContainer",componentId:"sc-1xmfwqk-0"})(["display:flex;flex-flow:column;justify-content:center;align-items:center;padding:10px;"]),t.BlogArticleItem=r.default.div.withConfig({displayName:"BlogArticleItem",componentId:"sc-1xmfwqk-1"})(["display:flex;flex-flow:column;align-items:center;justify-content:center;color:#555;"]),t.PublishNote=r.default.div.withConfig({displayName:"PublishNote",componentId:"sc-1xmfwqk-2"})(["display:flex;justify-content:flex-start;align-items:center;max-width:640px;margin:10px auto 20px auto;color:#555;"]),t.CoverImage=r.default.img.withConfig({displayName:"CoverImage",componentId:"sc-1xmfwqk-3"})(["max-width:640px;ju

TypeError: Object.values(...).map(...) is not a function
    at Object.defineProperty.value (/Users/patricklemiuex/projects/iflipd-reactql/dist/server.js:236:51991)
    at a (/Users/patricklemiuex/projects/iflipd-reactql/dist/server.js:1:172)
    at Object.<anonymous> (/Users/patricklemiuex/projects/iflipd-reactql/dist/server.js:236:51645)
    at a (/Users/patricklemiuex/projects/iflipd-reactql/dist/server.js:1:172)
    at /Users/patricklemiuex/projects/iflipd-reactql/dist/server.js:1:964
    at Object.<anonymous> (/Users/patricklemiuex/projects/iflipd-reactql/dist/server.js:1:975)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Function.Module.runMain (module.js:703:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:665:3
npm ERR! code ELIFECYCLE```

I'm definitely operating on an array, it's as if the server is getting called twice, or something really odd.. Not sure if you can shed any light, it's very frustrating.

Thanks for your time, i know this isn't your problem, it's a my problem, but any light you can shed will be appreciated
reduxdj commented 5 years ago

The problem was i had forgotten a semi-colon here

const scripts = Object.values(manifest).map((item) => item.match('.js'));