Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility problem of SSR with ES5 #3867

Closed
speedornothing opened this issue Oct 7, 2016 · 6 comments
Closed

compatibility problem of SSR with ES5 #3867

speedornothing opened this issue Oct 7, 2016 · 6 comments

Comments

@speedornothing
Copy link

speedornothing commented Oct 7, 2016

bundle rendering doesn't work if exports a function using module.exports = function(context).. instead of export default context => ... in server entry point . it throws an error:

TypeError: Cannot read property 'render' of undefined
at normalizeRender (node_modules\vue-server-renderer\build.js:5192:19)

it looks like a compatibility problem of bundle rendering with ES5.

I changed the codes in node_modules/vue-server-renderer/build.js to the following:

if(typeof m.exports === 'function'){
  resolve(m.exports(_context))
  return
}

var res = Object.prototype.hasOwnProperty.call(m.exports, 'default')
  ? m.exports.default
  : m

then it works.

@speedornothing
Copy link
Author

if needed, i could supply my test case

function renderCode(code, context, callback){
  var createBundleRenderer = require('vue-server-renderer').createBundleRenderer
  var renderer = createBundleRenderer(code)
  renderer.renderToString(context, callback)
}

it('bundle-rendering-es5-compatibility', function(done){
  var bundleCode = [
    'var Vue = require(\'vue\')',
    'module.exports = function(context){',
    '  return new Promise(function(resolve, reject){',
    '    resolve(new Vue({',
    '      template: \'<div id="app">app</div>\'',
    '    }))',
    '  })',
    '}'
  ].join('\n')

  renderCode(bundleCode, {}, function(err, html){
    if(err){
      done(err)
      return
    }
    try{
      html.should.equal('<div id="app" server-rendered="true">app</div>')
    } catch(e){
      done(e)
      return
    }
    done()
  })
})

@AlbertMarashi
Copy link

@yyx990803 why was this closed

@jacekkarczmarczyk
Copy link

Because if was fixed
image

You can create a new issue if you have reproduction showing that the bug still exists

@AlbertMarashi
Copy link

@jacekkarczmarczyk I'm using the new node 13 Import/Exports. Could this have anything to do with it?

@AlbertMarashi
Copy link

This only occurs when I am adding or removing a new import to a vue file, restarting the server fixes the issue. Not sure why this occurs

@jacekkarczmarczyk
Copy link

No idea, create a minimal reproduction and open a new issue or ask in discord/forum/etc

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

No branches or pull requests

3 participants