Skip to content

Exporting with app.mount should work in browser #650

Open
@YerkoPalma

Description

@YerkoPalma

Expected behavior

module.exports = app.mount('body') should work on the browser, with browsers APIs

Actual behavior

Using fetch ends up in fetch is not defined error which dissappears when I change module.exports = app.mount('body') with app.mount('body')

Steps to reproduce behavior

Run npx create-choo-app some-app and replace the main view with

var html = require('choo/html')

module.exports = view
var readme
function view (state, emit) {
  if (!readme) {
    fetch('../README.md')
    .then(response => response.text())
    .then(text => {
      readme = text
      emit('render')
    })
  }
  return html`
    <body class="sans-serif pa3">
      ${readme || html`<h2>Loading...</h2>`}
    </body>
  `
}

Then run npm start and it will throw something like

ReferenceError: fetch is not defined
    at Choo.view [as _handler] (/home/yerko/Dev/choo-talk/views/main.js:8:5)
    at Choo._prerender (/home/yerko/Dev/choo-talk/node_modules/choo/index.js:235:18)
    at Choo.toString (/home/yerko/Dev/choo-talk/node_modules/choo/index.js:209:19)
    at Object.module.exports.render (/home/yerko/Dev/choo-talk/node_modules/bankai/ssr/choo.js:66:7)
    at ServerRender.render (/home/yerko/Dev/choo-talk/node_modules/bankai/ssr/index.js:28:39)
    at Array.renderApp (/home/yerko/Dev/choo-talk/node_modules/bankai/lib/graph-document.js:54:11)
    at module.exports (/home/yerko/Dev/choo-talk/node_modules/run-waterfall/index.js:24:13)
    at documentifyRoute (/home/yerko/Dev/choo-talk/node_modules/bankai/lib/graph-document.js:47:5)
    at push (/home/yerko/Dev/choo-talk/node_modules/map-limit/index.js:46:5)
    at flush (/home/yerko/Dev/choo-talk/node_modules/map-limit/index.js:32:7)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions