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

No js document or window in Gatsby #12849

Closed
donaldboulton opened this issue Mar 25, 2019 · 3 comments
Closed

No js document or window in Gatsby #12849

donaldboulton opened this issue Mar 25, 2019 · 3 comments
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation

Comments

@donaldboulton
Copy link

donaldboulton commented Mar 25, 2019

I am learning Gatsby but most of the react components I try to build with npm modules that have anything about document or window create build errors. Like prism.js common for anyone to use gives me the following error
`error Building static HTML failed

See our docs page on debugging HTML builds for help https://gatsby.dev/debug-html

175 |
176 | highlightAll: function(async, callback) {

177 | _.highlightAllUnder(document, async, callback);
| ^
178 | },
179 |
180 | highlightAllUnder: function(container, async, callback) {

WebpackError: ReferenceError: document is not defined`

react-comments and many many more.
I have learned how to get around this in gatsby-browsers.js or html.js, with my old non $ jquery scripts, but how do you fix this for npm modules???

@gatsbot gatsbot bot added the type: documentation An issue or pull request for improving or updating Gatsby's documentation label Mar 25, 2019
@coreyward
Copy link
Contributor

coreyward commented Mar 25, 2019

@donaldboulton
Copy link
Author

donaldboulton commented Mar 25, 2019

Nice thanks for the reply, I will try that and get back to this.
Thanks
DOnald Boulton

@donaldboulton
Copy link
Author

donaldboulton commented Mar 25, 2019

Example with the below worked
if (typeof window !== undefined) { const module = require('prismjs') }

Adding to gatsby-node.js as [Gatsby]https://www.gatsbyjs.org/docs/debugging-html-builds/#how-to-check-if-window-is-defined) gave me the following error
` exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {

101 | if (stage === "build-html" {
| ^
102 | actions.setWebpackConfig({
103 | module: {
104 | rules: [
error Command failed with exit code 1.`

Thanks for the info but I would still like to be able to tell webpack to overlook window and document errors in modules because some of the npm modules having document as a error being undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

No branches or pull requests

2 participants