Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitemap is not a constructor while using react-router-sitemap

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?

like image 957
anonn023432 Avatar asked Oct 18 '22 14:10

anonn023432


1 Answers

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.

like image 129
Jatin Gupta Avatar answered Oct 27 '22 10:10

Jatin Gupta