jshemas / openGraphScraper

Node.js scraper service for Open Graph Info and More!
MIT License
643 stars 102 forks source link

Module not found: Can't resolve 'http2' #158

Closed qhkm closed 1 year ago

qhkm commented 1 year ago

Environment

Node ver: 16.8.0 Next ver: 12 Npm ver: 8.19.2 open-graph-scraper: ^5.0.3

I just finished installing the lib and when I tried to use it, this error was thrown.

./node_modules/http2-wrapper/source/agent.js:7:0
Module not found: Can't resolve 'http2'

Import trace for requested module:
./node_modules/http2-wrapper/source/index.js
./node_modules/got/dist/source/core/options.js
./node_modules/got/dist/source/index.js
./node_modules/open-graph-scraper/lib/utils.js
./node_modules/open-graph-scraper/lib/openGraphScraper.js
./node_modules/open-graph-scraper/index.js
./src/components/life/input-field.tsx
./src/pages/life/[wtdId]/index.tsx

https://nextjs.org/docs/messages/module-not-found

Then I tried installing the missing http2 module and then another error was thrown

Module not found: Can't resolve 'net'

Import trace for requested module:
./node_modules/http2-wrapper/source/auto.js
./node_modules/http2-wrapper/source/index.js
./node_modules/got/dist/source/core/options.js
./node_modules/got/dist/source/index.js
./node_modules/open-graph-scraper/lib/utils.js
./node_modules/open-graph-scraper/lib/openGraphScraper.js
./node_modules/open-graph-scraper/index.js
./src/components/life/input-field.tsx
./src/pages/life/[wtdId]/index.tsx

And installed net lib yet another error thrown

node:buffer
Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.

Any idea what's wrong?

jshemas commented 1 year ago

Hello,

Unfortunately, it looks like there is no way to solve this problem without a significant rewrite or a second library. Originally I was under the impression that you could still use this library in the browser as long as you didn’t make any requests, but it looks like that is not possible because when you build your project, it will still try and pull in the request library(got), which is causing your issue.

I've updated my readme to state we do not support bowser usage at this time.

I would recommend trying to use https://github.com/sindresorhus/ky for requests and use https://github.com/microlinkhq/metascraper to get the meta data.