Open alessandrojcm opened 5 years ago
Hi @alessandrojcm ,
it's a classic issue with Gatsby and production build process. The workaround it to wrap all use of document
or window
element with the following code
if (typeof document !== 'undefined') {
}
or
if (typeof window !== 'undefined') {
}
I am getting the same issue, when I launch the server in production mode. I am using razzle (which uses webpack to build)
The problem is that it is the import of bulma itself that causes the problem, I cannot wrap the import as suggested above, because imports need to be top level.
import "bulma-carousel/dist/css/bulma-carousel.min.css";
import bulmaCarousel from 'bulma-carousel' //<--- line alone causse the crash
yarn start:prod
yarn run v1.15.2
$ NODE_ENV=production node build/server.js
/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:1186
var isIE = window.navigator.pointerEnabled || window.navigator.msPointerEnabled;
^
ReferenceError: window is not defined
at Object.<anonymous> (/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:1186:12)
at __webpack_require__ (/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:30:30)
at Object.isIE (/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:1018:72)
at __webpack_require__ (/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:30:30)
at Object.prefix (/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:460:79)
at __webpack_require__ (/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:30:30)
at /home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:73:18
at /home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:76:10
at webpackUniversalModuleDefinition (/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:3:20)
at Object.<anonymous> (/home/maxou/dev/vizmmt/node_modules/bulma-carousel/dist/js/bulma-carousel.js:10:3)
error Command failed with exit code 1.
If I'm mot mistaken, this will crash all apps that uses server side rendering: https://github.com/Wikiki/bulma-carousel/blob/master/src/js/utils/device.js
I know this is not a fix per se, but I needed to get the carousel on the web ASAP; so I changed to react-slick and it worked great. It lets you pass custom components for the carousel's arrow; so you can easily style your components with bulma's icons.
This is my work around until the issue gets fixed, the line :
import bulmaCarousel from 'bulma-carousel'
is replaced by :
const bulmaCarousel = (() => {
if (typeof window !== 'undefined') {
return require('bulma-carousel')
}
})()
Hi there, I'm trying to use bulma carousel with Gatsby 2 but I', getting the following error when trying to build production HTML:
Here's the component that uses the carousel:
And here are my dependencies:
I'm using Node 10.15.1 on Arch Linux 64 bits, if that may be of help. Also note that, in develop builds (i.e running
gatsby develop
) the carousel works just fine.