microlinkhq / metascraper

Get unified metadata from websites using Open Graph, Microdata, RDFa, Twitter Cards, JSON-LD, HTML, and more.
https://metascraper.js.org
MIT License
2.35k stars 168 forks source link

Can I use 'import' instead of 'require'? #453

Closed sebpowell closed 3 years ago

sebpowell commented 3 years ago

Prerequisites

Subject of the issue

I'm trying to convert the 'require' syntax shown in the documentation to 'import', but not having any luck. Here's my code:

import createMetaScraper from 'metascraper';
import metascraperAuthor from 'metascraper-author';

const metascraper = createMetaScraper([metascraperAuthor()]);

This gives me the following error:

TypeError: (0 , metascraper_author_1.default) is not a function

Not sure where I'm going wrong? Any guidance would be greatly appreciated.

Kikobeats commented 3 years ago

The library is using CJS, it's not ready for ESM.

I think it must be possible if you load https://github.com/standard-things/esm first.

sebpowell commented 3 years ago

@Kikobeats great, thanks!