OP-Engineering/link-preview-js

Version 2.1.5 broke our usage of require

uculrich opened this issue · 4 comments

Hello,

With version 2.1.5 (or 2.1.4) there was this change in the package.json:

  "exports": {
    "import": "build/index.js"
  },

We are using this awesome library in our CommonJS node service and import the main functions like this:

const {getLinkPreview} = require('link-preview-js');

Now with the newest changes we are getting this error

internal/modules/cjs/loader.js:595
    throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
    ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in /our-service/node_modules/link-preview-js/package.json

Adding

  "exports": {
    "require": "./build/index.js",
    "import": "build/index.js"
  },

to the package.json seems to resolve the issue as it probably makes the exports available for require too.

I am quite new to the "exports" property in the package.json and the js import world, so I am not sure if there was an intention to only make this lib available for ES modules? Or is it possible to have this change in the library? Would be happy to provide a proper PR if needed as well.
Or is there another way that we can require the functions?

Thank you in advance on your opinion / advice!

I'll apply your changes right away, I'm also not sure what is the correct setting here, I was just following the instructions for Skypack

Done, 2.1.6, can you try it and let me know if it's working?

Awesome thanks for the quick fix, will try it right away

Works great, thanks a lot!!