I'm trying to create a sitemap for my React website and I'm using react-router-sitemap
for the same. Here is my sitemap-builder.js
:
require('babel-register');
//import React from 'react';
// import { render } from 'react-dom';
//import Sitemap from 'react-router-sitemap';
const router = require('./root.js').default;
const Sitemap = require('./').default;
const filterConfig = {
isValid: false,
rules: [
/\/admin/
],
};
(
new Sitemap(router)
.filterPaths(filterConfig)
.build('https://www.ace-up.com')
.save('./sitemap.xml')
);
And my package.json
has the following:
"scripts": {
"build:sitemap": "node ./js/sitemap-builder.js"
},
So I just run it through my terminal using the command: npm run build:sitemap
but it gives me the following error:
new Sitemap(router)
^
TypeError: Sitemap is not a constructor
And I have installed the module also; I can see it in my package.json
. Why is the error coming up and how can correct it?
You are importing the Sitemap constructor wrong.
Change this line:
const Sitemap = require('./').default;
to this:
const Sitemap = require('react-router-sitemap').default;
Should work now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With