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

Unable to generate sitemap.xml file #117

Open
oquidave opened this issue Feb 23, 2022 · 3 comments
Open

Unable to generate sitemap.xml file #117

oquidave opened this issue Feb 23, 2022 · 3 comments

Comments

@oquidave
Copy link

I am trying to implement sitemap for my react app. I am new to react and babel. I have followed through the example given. Everything seems to work just fine. However, for some reason, the sitemap.xml isn't generated at all in the specified folder. File permissions used to be fine. I am wondering why this is the issue.

//router.js

import React from 'react';
import { Switch, Route } from 'react-router-dom';

export default (
<Switch>
    <Route path='/' />
    <Route path='/about' />
    <Route path='/projects' />
    <Route path='/contacts' />
    <Route path='/auth' />

</Switch>
);

// sitemap-builder.js

require("babel-register")({
    presets: ["es2015", "react"]
}) 

const Sitemap = require('react-router-sitemap').default;
const router = require('./router').default;

function generateSitemap() {

    return (
        new Sitemap(router)
            .build('http://localhost:3000')
            .save('./public/sitemap.xml')
    );
}

generateSitemap();

//package.json

 "scripts": {
     .....
    "sitemap": "babel sitemap-builder.js"
  },

 "devDependencies": {
    "@babel/cli": "^7.17.6",
    "@babel/core": "^7.17.5",
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "@babel/register": "^7.17.0",
  }

//.bashrc file

{
    "ignore": [
		"node_modules/**/*"
	],
	"presets": [
		"@babel/preset-env",
		"@babel/preset-react"
	]
}

//yarn sitemap output

yarn sitemap               
yarn run v1.21.1
warning ../package.json: No license field
$ babel sitemap-builder.js
"use strict";

require("babel-register")({
    presets: ["es2015", "react"]
}) 

var Sitemap = require('react-router-sitemap').default;

var router = require('./router').default;

function generateSitemap() {
  return new Sitemap(router).build('http://localhost:3000').save('./public/sitemap.xml');
}

generateSitemap();

Done in 0.95s.
@oquidave
Copy link
Author

Problem fixed by myself. Had to do with babel setup. First had to change the "sitemap": "babel sitemap-builder.js" to "sitemap": "babel-node sitemap-builder.js" and deleted the .babelrc file! Script is now being executed instead of simply being shown.

@abhijain2003
Copy link

gn
Screenshot 2022-06-01 170338
Screenshot 2022-06-01 170357
Screenshot 2022-06-01 170414

I am building a blog website where i am fetching data from my API you can see on picture
I am running react-router-sitemap and I did exactly same as mentioned in above chat. still I got this error of unexpected token

help me resolving this please

@Ayushraikwar
Copy link

gn Screenshot 2022-06-01 170338 Screenshot 2022-06-01 170357 Screenshot 2022-06-01 170414

I am building a blog website where i am fetching data from my API you can see on picture I am running react-router-sitemap and I did exactly same as mentioned in above chat. still I got this error of unexpected token

help me resolving this please

I'm getting the exact issue, i.e, The Issues caused by Spread Operator :'( :'(

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

3 participants