-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Document is not defined #11885
Comments
@Dogtiti can you share a repo with the code you're using? Or a dummy repository that demonstrates this issue? |
@Dogtiti i've created a new Gatsby website based on the hello world starter, just to get a bare bones site up and running. import React, { Component } from 'react'
import { G2, Chart, Geom, Axis, Tooltip, Coord, Label, Legend, View, Guide, Shape, Facet, Util } from 'bizcharts'
import DataSet from '@antv/data-set'
class Page2 extends Component {
state = {
chartData: [
{
year: '1986',
ACME: 162,
Compitor: 42,
},
{
year: '1987',
ACME: 134,
Compitor: 54,
},
{
year: '1988',
ACME: 116,
Compitor: 26,
},
{
year: '1989',
ACME: 122,
Compitor: 32,
},
{
year: '1990',
ACME: 178,
Compitor: 68,
},
{
year: '1991',
ACME: 144,
Compitor: 54,
},
{
year: '1992',
ACME: 125,
Compitor: 35,
},
{
year: '1993',
ACME: 176,
Compitor: 66,
},
{
year: '1994',
ACME: 156,
},
{
year: '1995',
ACME: 195,
},
{
year: '1996',
ACME: 215,
},
{
year: '1997',
ACME: 176,
Compitor: 36,
},
{
year: '1998',
ACME: 167,
Compitor: 47,
},
{
year: '1999',
ACME: 142,
},
{
year: '2000',
ACME: 117,
},
{
year: '2001',
ACME: 113,
Compitor: 23,
},
{
year: '2002',
ACME: 132,
},
{
year: '2003',
ACME: 146,
Compitor: 46,
},
{
year: '2004',
ACME: 169,
Compitor: 59,
},
{
year: '2005',
ACME: 184,
Compitor: 44,
},
],
chartheight: 600,
}
componentDidMount() {
if (typeof window !== 'undefined') {
this.setState({ chartheight: window.innerHeight })
window.addEventListener('resize', this.handleWindowSizeChange)
}
}
componentWillUnmount() {
if (typeof window !== 'undefined') {
window.removeEventListener('resize', this.handleWindowSizeChange)
}
}
handleWindowSizeChange = () => {
this.setState({
chartheight: window.innerHeight,
})
}
render() {
const { chartData, chartheight } = this.state
var dv = new DataSet.View().source(chartData)
dv.transform({
type: 'fold',
fields: ['ACME', 'Compitor'],
key: 'type',
value: 'value',
})
const chartscale = {
value: {
alias: 'The Share Price in Dollars',
formatter: function(val) {
return '$' + val
},
},
year: {
range: [0, 1],
},
}
return(
<div>
<Chart height={chartheight} data={dv} padding={'auto'} scale={chartscale} forceFit>
<Tooltip crosshairs />
<Axis />
<Legend />
<Geom type="area" position="year*value" color="type" shape="smooth" />
<Geom type="line" position="year*value" color="type" shape="smooth" size={2} />
</Chart>
</div>
)
}
}
export default Page2 Issuing Issuing error Building static HTML failed
See our docs page on debugging HTML builds for help https://gatsby.app/debug-html
4 | * @return {HTMLElement} DOM 节点
5 | */
> 6 | var TABLE = document.createElement('table');
| ^
7 | var TABLE_TR = document.createElement('tr');
8 | var FRAGMENT_REG = /^\s*<(\w+|!)[^>]*>/;
9 | var CONTAINERS = {
WebpackError: ReferenceError: document is not defined
- create-dom.js:6 Object../node_modules/@antv/util/lib/dom/create-dom.js
[lib]/[@antv]/util/lib/dom/create-dom.js:6:1
- bootstrap:19 __webpack_require__
lib/webpack/bootstrap:19:1
- common.js:31 Object../node_modules/@antv/g/lib/util/common.js
[lib]/[@antv]/g/lib/util/common.js:31:14
- bootstrap:19 __webpack_require__
lib/webpack/bootstrap:19:1
- index.js:1 Object../node_modules/@antv/g/lib/util/index.js
[lib]/[@antv]/g/lib/util/index.js:1:18
- bootstrap:19 __webpack_require__
lib/webpack/bootstrap:19:1
- canvas.js:1 Object../node_modules/@antv/g/lib/canvas.js
[lib]/[@antv]/g/lib/canvas.js:1:12
- bootstrap:19 __webpack_require__
lib/webpack/bootstrap:19:1
- index.js:2 Object../node_modules/@antv/g/lib/index.js
[lib]/[@antv]/g/lib/index.js:2:11
- bootstrap:19 __webpack_require__
lib/webpack/bootstrap:19:1
- renderer.js:1 Object../node_modules/@antv/g2/lib/renderer.js
[lib]/[@antv]/g2/lib/renderer.js:1:9
- bootstrap:19 __webpack_require__
lib/webpack/bootstrap:19:1
- core.js:3 Object../node_modules/@antv/g2/lib/core.js
[lib]/[@antv]/g2/lib/core.js:3:9
- bootstrap:19 __webpack_require__
lib/webpack/bootstrap:19:1
- index.js:3 Object../node_modules/bizcharts/es6/index.js
[lib]/[bizcharts]/es6/index.js:3:13
- bootstrap:19 __webpack_require__
lib/webpack/bootstrap:19:1 Doing a bit of searching led me to this and reading the comments in there to this. With that, it looks like that the package is not ssr (server side rendering) friendly, with that not "gatsby friendly". Feel free to provide feedback |
@jonniebigodes excellent debugging! @Dogtiti you'll want to check out this document and add bizcharts to the ignored list like shown. If you're able, I'd recommend swapping to an SSR friendly charting library, but if you're unable you can remediate like so. Going to close this out--but please feel free to comment and we'll re-open if we can help further! Thanks for using Gatsby 💜 |
Description
Successfully run in
gatsby develop
,but failed atgatsby build
Steps to reproduce
I have used
bizcharts
,it caused the problem,and thepackage.json
:Expected result
Successfully run
gatsby build
Actual result
Environment
The text was updated successfully, but these errors were encountered: