mistval / node-fetch-cache

Node-fetch with built-in response caching.
MIT License
55 stars 9 forks source link

Attempted import error: 'URLSearchParams' is not exported from 'url' #20

Closed gkpo closed 1 year ago

gkpo commented 2 years ago

Hi, I'm using node-fetch-cache to deploy a site on vercel and I'm having this issue during deploy:

./node_modules/node-fetch-cache/src/index.js Attempted import error: 'URLSearchParams' is not exported from 'url' (imported as 'URLSearchParams').

Here's my package.json:

{
  "name": "[masked]",
  "version": "1.0.0",
  "description": "[masked]",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "postbuild": "next-sitemap",
    "fonts": "fontello-cli install --config ./fontello-config.json --font ./public/font --css ./public/css"
  },
  "repository": {
    "type": "git",
    "url": "[masked]"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/[masked]"
  },
  "homepage": "https://github.com/[masked]",
  "dependencies": {
    "@next/bundle-analyzer": "^10.1.2",
    "axios": "^0.21.1",
    "classnames": "^2.2.6",
    "cookie": "^0.4.1",
    "dayjs": "^1.10.4",
    "imagemin-mozjpeg": "^8.0.0",
    "imagemin-optipng": "^7.1.0",
    "imagemin-svgo": "^7.1.0",
    "isomorphic-unfetch": "^3.0.0",
    "js-cookie": "^2.2.1",
    "lodash": "^4.17.19",
    "mixpanel-browser": "^2.39.0",
    "next": "^11.1.2",
    "node-fetch-cache": "^3.0.4",
    "node-html-parser": "^1.4.9",
    "nookies": "^2.2.4",
    "nprogress": "^0.2.0",
    "numeral": "^2.0.6",
    "probe-image-size": "^6.0.0",
    "react": "^17.0.2",
    "react-copy-to-clipboard": "^5.0.2",
    "react-dom": "^17.0.2",
    "react-fade-in": "^1.1.1",
    "react-gtm": "github:Vadorequest/react-gtm#2.0.0",
    "react-hook-form": "^6.9.5",
    "react-html-parser": "^2.0.2",
    "react-lazy-load-image-component": "^1.4.1",
    "react-lazyload": "^3.0.0",
    "react-mailchimp-subscribe": "^2.1.0",
    "react-masonry-css": "^1.0.14",
    "react-modal-video": "^1.2.5",
    "react-multistep-wizard": "^3.0.1",
    "react-slick": "^0.27.3",
    "recharts": "^1.8.5",
    "sass": "^1.26.5",
    "simple-react-lightbox": "^3.6.9-0",
    "slick-carousel": "^1.8.1",
    "smoothscroll": "^0.4.0"
  },
  "devDependencies": {
    "fontello-cli": "^0.6.2",
    "next-sitemap": "^1.2.4"
  }
}

Found this thread: https://github.com/Azure/azure-sdk-for-js/issues/7381 But installing node/types doesn't solve my problem...

Any idea where this can come from ?

mistval commented 2 years ago

Hello, I'm not familiar with Vercel and that error is rather strange, almost like its injecting its own version of the url module. URLSearchParams is a global class now though, so importing it is not even necessary (as of Node v10). So I have removed the import and pushed new version v3.0.5 to npm. You can try installing it with npm install node-fetch-cache@latest and maybe it will work for you.

gkpo commented 2 years ago

Omg thanks so much for that reactivity ⚡️ That solved my issue :)

gkpo commented 2 years ago

Argh, seems that I got happy too fast.. Now the deploy process works fine, except I have this error during runtime

Unhandled Runtime Error
TypeError: The "original" argument must be of type Function

Call Stack
promisify
node_modules/util/util.js (614:0)
eval
node_modules/@npmcli/move-file/index.js (25:0)
Object../node_modules/@npmcli/move-file/index.js
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/pages/_app.js (716:1)
Object.options.factory
/_next/static/chunks/webpack.js (685:31)
__webpack_require__
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (354:21)
eval
node_modules/cacache/lib/entry-index.js (16:17)
Object../node_modules/cacache/lib/entry-index.js
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/pages/_app.js (1598:1)
Object.options.factory
/_next/static/chunks/webpack.js (685:31)
__webpack_require__
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (354:21)
eval
node_modules/cacache/ls.js (3:14)
Object../node_modules/cacache/ls.js
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/pages/_app.js (1686:1)
Object.options.factory
/_next/static/chunks/webpack.js (685:31)
__webpack_require__
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (354:21)
eval
node_modules/cacache/index.js (3:11)
Object../node_modules/cacache/index.js
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/pages/_app.js (1543:1)
Object.options.factory
/_next/static/chunks/webpack.js (685:31)
__webpack_require__
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (354:21)
eval
webpack-internal:///./node_modules/node-fetch-cache/src/classes/caching/file_system_cache.js (5:65)
Module../node_modules/node-fetch-cache/src/classes/caching/file_system_cache.js
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/pages/_app.js (4513:1)
Module.options.factory
/_next/static/chunks/webpack.js (685:31)
__webpack_require__
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (354:21)
eval
webpack-internal:///./node_modules/node-fetch-cache/src/index.js (13:95)
Module../node_modules/node-fetch-cache/src/index.js
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/pages/_app.js (4557:1)
Module.options.factory
/_next/static/chunks/webpack.js (685:31)
__webpack_require__
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (354:21)
eval
webpack-internal:///./pages/_app.js (10:74)
Module../pages/_app.js
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/pages/_app.js (40:1)
Module.options.factory
/_next/static/chunks/webpack.js (685:31)
__webpack_require__
file:///Users/guillaume/dev/mecanicus/app/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (354:21)
eval
node_modules/next/dist/build/webpack/loaders/next-client-pages-loader.js?page=%2F_app&absolutePagePath=private-next-pages%2F_app! (5:15)
eval
node_modules/next/dist/client/route-loader.js (207:48)
mistval commented 2 years ago

That looks to me like it's trying to compile this module into your frontend code. Is that your intention? If so, I'm afraid this module will only work in backend Node.js code, it won't run in a browser.

gkpo commented 2 years ago

yes this code is definitely supposed to be run on the server side... I don't get it, I guess that's a question for next.js community. Regardless, thanks a lot for your help :)