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

add history build error! #131

Closed
lentg opened this issue Jun 22, 2017 · 1 comment
Closed

add history build error! #131

lentg opened this issue Jun 22, 2017 · 1 comment

Comments

@lentg
Copy link

lentg commented Jun 22, 2017

"dependencies": {
  "history": "^4.6.3",
  "preact-compat": "^3.16.0",
  "preact-router": "^2.5.2"
}
lsdeiMac:vds ls$ yarn build
yarn build v0.24.5
$ preact build 
Build [==================  ] 91% (2.1s) additional asset processing
  Total precache size is about 164 kB for 15 resources.
Template execution failed: Invariant Violation: Hash history needs a DOM
  Error: Invariant Violation: Hash history needs a DOM
  
  - invariant.js:42 invariant
    [vds]/[invariant]/invariant.js:42:15
  
  - createHashHistory.js:69 Object.createHashHistory
    [vds]/[history]/createHashHistory.js:69:27
  
  - app.js:22 App.render
    /Users/ls/web/vds/src/components/app.js:22:30
  
  - index.js:92 renderToString
    [vds]/[preact-render-to-string]/src/index.js:92:18
  
  - prerender.js:59 prerender
    [vds]/[preact-cli]/lib/lib/prerender.js:59:13
  
  - webpack-config.js:356 Object.ssr
    [vds]/[preact-cli]/lib/lib/webpack-config.js:356:54
  
  - template.html:109 EM6I.module.exports
    [vds]/[preact-cli]/lib/resources/template.html:109:37
  
  - index.js:265 
    [vds]/[html-webpack-plugin]/index.js:265:16
  
  - util.js:16 tryCatcher
    [vds]/[html-webpack-plugin]/[bluebird]/js/release/util.js:16:23
  
  - promise.js:512 Promise._settlePromiseFromHandler
    [vds]/[html-webpack-plugin]/[bluebird]/js/release/promise.js:512:31
  
  - promise.js:569 Promise._settlePromise
    [vds]/[html-webpack-plugin]/[bluebird]/js/release/promise.js:569:18
  
  - promise.js:606 Promise._settlePromiseCtx
    [vds]/[html-webpack-plugin]/[bluebird]/js/release/promise.js:606:10
  
  - async.js:138 Async._drainQueue
    [vds]/[html-webpack-plugin]/[bluebird]/js/release/async.js:138:12
  
  - async.js:143 Async._drainQueues
    [vds]/[html-webpack-plugin]/[bluebird]/js/release/async.js:143:10
  
  - async.js:17 Immediate.Async.drainQueues
    [vds]/[html-webpack-plugin]/[bluebird]/js/release/async.js:17:14
  

error Command failed with exit code 1.
@rkostrzewski
Copy link
Collaborator

Preact CLI prerenders your index.html with initial route for better end user performance - however it does so in nodejs, so document is not available.

You could either:

  • disable prerender by running preact build --no-prerender
  • conditionaly import the library checking if DOM is available
if (typeof document !== void 0) {
  const history = require('history')
  ...do stuff with history...
}

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

2 participants