Home > Blockchain >  Gatsby socket and commons.js error when loading website
Gatsby socket and commons.js error when loading website

Time:12-21

I've followed this helpful answer: how do you clone a git Gatsby project and run it locally? to load up a demo Gatsby project on git.

But I get the following error:

localhost/:1 
        
       GET http://localhost:9000/socket.io/socket.io.js net::ERR_ABORTED 404 (Not Found)
(index):5 
        
       GET http://localhost:9000/commons.js net::ERR_ABORTED 404 (Not Found)

This is what I've done

git clone https://github.com/MunifTanjim/gatsby-theme-dox
cd gatsby-theme-dox
npm install #or yarn install
cd demo
gatsby develop #to build the site in development mode
gatsby build && gatsby serve #to build the site in production mode

Then I added a 404.html page to the demo/public directory since I was getting an error on gatsby serve But now, all I'm getting is a blank website with the error I indicated above. I'm very much a beginner in Gatsby and I'd like to get this demo running on my local machine.

Thanks

CodePudding user response:

Then I added a 404.html page to the demo/public directory since

The /public folder is the one that is automatically generated in each build from the code from the source (/src) folder. You must not place code there, otherwise, in each build, it will be lost. Take a look at the docs:

/public Automatically generated. The output of the build process will be exposed inside this folder. Should be added to the .gitignore file if not added already.

If you want to create a custom 404 page, you can create one by creating a 404.js file inside src/pages.

Regarding your main issue, the fact that the output spots a localhost:9000 (port 9000) indicates that you used gatsby build, not gatsby develop (otherwise the port would be the 8000). Using the first one (gatsby build) you'll need to rebuild the whole site to see the changes while running gatsby develop you'll see instantly the changes you made (unless you change the data sources) because of the hot reload feature.

Your issue appears because there's no socket.io.js file, so it throws a 404 error (not found).

I'd suggest:

  • Refresh the cache by running gatsby clean
  • Make sure the yarn install or the npm install finished without errors (all dependencies installed properly)
  • Run gatsby develop
  • Make some "live" changes and once you feel comfortable enough proceed with the following commands.
  • Run again gatsby build
  • Serve the site by gatsby serve (this will make your site live locally under localhost:9000)

More recommendations can be found in this GitHub thread.

I'd recommend you, as I pointed in your previous answer, read the gatsby-cli docs to know what you are doing in each command.

  • Related