lgraubner / sitemap-generator

Easily create XML sitemaps for your website.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: mitt is not a function

SergiusSidorov opened this issue · comments

Do you want to request a feature or report a bug?
bug

What is the current behavior?
Error: TypeError: mitt is not a function

If the current behavior is a bug, please provide the steps to reproduce.

export const sitemap = (host: string) => new Promise<string>((resolve, reject) => {
  var generator = SitemapGenerator(host, {
    crawlerMaxDepth: 3,
    stripQuerystring: false
  });

  generator.on('done', (stats) => {
    console.log(`sitemap generation finished: ${stats}`);
    return resolve(stats);
  });

  generator.on('error', (err) => {
    console.log(`sitemap generator error: ${err}`);
    return reject(err);
  });

  generator.on('ignore', (url) => {
    console.log(`sitemap generator will ignore url: ${url}`); 
  });

  console.log(`sitemap generator crawler starting on ${host}`);
  generator.start();
});

sitemap("localhost:4000")
        .then(a => console.log('ok'))
        .catch(err => console.log(`error: ${err}`));

What is the expected behavior?
Generated sitemap.xml

Hi! I cannot reproduce your problem. Are you sure all dependencies are installed correctly? mitt is a dependency of sitemap-generator.
Are you trying to use this package in the browser (export is more common for browser development ;))? This package is meant to be used only with Node.js.

Do you want to request a feature or report a bug?
bug

What is the current behavior?
should be working as expected with Angular server side rendering

If the current behavior is a bug, please provide the steps to reproduce.
I am not sure it's a bug or am missing something from documentation.
Steps to reproduce :-
Download the finished sample code from the Universal Guide.
Unzipped and installed dependencies (with npm install).
Enabled SW with ng add @angular/pwa --project=angular.io-example.
Built with npm run build:ssr.
Run with npm run serve:ssr.

then just added your sitemap-generator sample integration code in server.ts
now build with npm run build:ssr
Run with npm run serve:ssr

What is the expected behavior?
TypeError: mitt is not a function

I don't think you are using it right. You should run the sitemap-generator after you created your site generating SSR stuff etc. This is a crawler and not intended to use during a build process.

@lgraubner Thanks for clarification can you please provide the working example or point to it with Angular or Angular Universal (Server side rendering) any help will greatly appropriated.

It doesn't matter what you use for your stack. The important thing is, that you use SSR, what you are obviously doing. Deploy your app as you would normally and create the sitemap afterwards. Simplest way would be to use the CLI.

yes I see. I don't think I what exactly am missing here. I am using the Complete Angular Universal SSR as given here
I just see after that command my site link is http://www.example.com/

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://www.example.com/</loc>
  </url>
</urlset>