cloudinary / cloudinary_npm

Cloudinary NPM for node.js integration
629 stars 323 forks source link

Webpack on nextjs always throws depency warnings #600

Closed marketsystems closed 1 year ago

marketsystems commented 1 year ago

Everything is latest version, these warnings are very annoying

"dependencies": { "autoprefixer": "10.4.14", "cloudinary": "^1.36.1", "eslint": "8.38.0", "eslint-config-next": "13.3.0", "exifr": "^7.1.3", "next": "13.3.0", "next-cloudinary": "^4.3.0", "postcss": "8.4.21", "react": "18.2.0", "react-dom": "18.2.0", "react-photo-album": "^2.0.3", "sharp": "^0.32.0", "tailwindcss": "3.3.1" }

npm run build

warn - ./node_modules/cloudinary/lib-es5/utils/index.js Critical dependency: the request of a dependency is an expression

Import trace for requested module: ./node_modules/cloudinary/lib-es5/utils/index.js ./node_modules/cloudinary/lib-es5/utils/srcsetUtils.js ./node_modules/cloudinary/lib-es5/cloudinary.js ./node_modules/cloudinary/cloudinary.js ./utils/cloudinary.js ./utils/getimages.js ./app/page.js

./node_modules/cloudinary/lib/utils/index.js Critical dependency: the request of a dependency is an expression

Import trace for requested module: ./node_modules/cloudinary/lib/utils/index.js ./node_modules/cloudinary/lib/utils/srcsetUtils.js ./node_modules/cloudinary/lib/cloudinary.js ./node_modules/cloudinary/cloudinary.js ./utils/cloudinary.js ./utils/getimages.js ./app/page.js

ondrejhudek commented 1 year ago

+1

marketsystems commented 1 year ago

seems like nobody wants to fix it

tamaracloudinary commented 1 year ago

Hi @ondrejhudek, @marketsystems Sorry for the late reply, we opened an internal ticket regarding your request. We will keep you updated here and let you know once it's deployed. Thanks! Tamara

mmachatschek commented 1 year ago

@tamaracloudinary this issue originates from the utils/index.js optionalRequire() function. webpack doesn't like requiring dynamic dependencies. As this function is only used for the proxy-agent stuff, it probably would make sense to write a workaround for only this optional dependency.

tamaracloudinary commented 1 year ago

@mmachatschek thank you, I've forwarded it to the team. We will keep you updated here and let you know once it's deployed. Thanks! Tamara

jackvane commented 1 year ago

+ 1, please fix this.

tamaracloudinary commented 1 year ago

Hi, I'm happy to share that the fix will be deployed at the next sprint, we will update here once it's deployed. Thanks for letting us know! Kind regards, Tamara

marketsystems commented 1 year ago

well over a month more like a leisurely jog :D :D

cloudinary-pkoniu commented 1 year ago

Hi everyone! Sorry for the delay in fixing the issue. Please try using the sdk in the latest version and let us know if it fixed the issue for you, so we can close it.

Cheers!

spencersmb commented 1 year ago

Had to revert back to 1.36.1 because it was completely breaking my next.js app. i'm using Next.js v 13.4.4 and was getting all the warnings as previously mentioned still, but it was unable to locate a file in "/app/blog/bridge.js", even though the only file in my folder structure is app/blog/page.tsx.

Hope this helps figure out the issue.

tamaracloudinary commented 1 year ago

Hi @spencersmb, Thank you for providing us with your valuable feedback. I assure you that I will ensure our development team receives this feedback.

roberto-duran commented 1 year ago

thanks, it was driving me crazy... i have same sceneraio next 13.4.4/app dir and with vr: 1.37.1 its not working

cloudinary-pkoniu commented 1 year ago

Hi @spencersmb and @roberto-duran,

Thanks for reaching out.

In order to reproduce the issue, I need some more information. Can I please ask you to provide more details about the problem you're encountering?

I know that you're using next.js@13.4.4 and cloudinary@1.37.1 but can you please confirm your current node.js version?

Also what would really help me, would be some kind of a runnable snippet that breaks for you. I've set up a basic webpack (version 5.86.0) project with cloudinary@1.37.1 as a dependency and I'm not getting any similar errors to you. Also, the warnings mentioned by the OP are gone as well.

Looking forward to your response.

Best, Patryk

filipposwift commented 1 year ago

Hi cloudinary-pkoniu I have the same problem with the following configuration:

Node: v18.14.2 Pnpm: v8.6.2

package.json: "dependencies": { "@types/node": "20.3.1", "@types/react": "18.2.13", "@types/react-dom": "18.2.6", "autoprefixer": "10.4.14", "cloudinary": "^1.37.2", "eslint": "8.43.0", "eslint-config-next": "13.4.6", "next": "13.4.6", "postcss": "8.4.24", "react": "18.2.0", "react-dom": "18.2.0", "react-hot-toast": "^2.4.1", "tailwindcss": "3.3.2", "typescript": "5.1.3" }

This is the function calling cloudinary:

import { v2 as cloudinary } from 'cloudinary'

async function getDesignerFolders() { cloudinary.config({ cloud_name: 'mycloudname', api_key: process.env.CLOUDINARY_API_KEY }) const cloudinaryData = await cloudinary.api.sub_folders('/somefolders') const folders = cloudinaryData.folders.map((folder: any) => folder.name)

return folders }

and this is the full error trace:

Import trace for requested module: ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/compiler.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/script.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/main.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/index.js ./node_modules/.pnpm/degenerator@3.0.4/node_modules/degenerator/dist/src/index.js ./node_modules/.pnpm/pac-resolver@5.0.1/node_modules/pac-resolver/dist/index.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/agent.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/index.js ./node_modules/.pnpm/proxy-agent@5.0.0/node_modules/proxy-agent/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/utils/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/cloudinary.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/cloudinary.js ./app/shopify/page.tsx

./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/resolver-compat.js Critical dependency: the request of a dependency is an expression

Import trace for requested module: ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/resolver-compat.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/main.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/index.js ./node_modules/.pnpm/degenerator@3.0.4/node_modules/degenerator/dist/src/index.js ./node_modules/.pnpm/pac-resolver@5.0.1/node_modules/pac-resolver/dist/index.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/agent.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/index.js ./node_modules/.pnpm/proxy-agent@5.0.0/node_modules/proxy-agent/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/utils/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/cloudinary.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/cloudinary.js ./app/shopify/page.tsx (node:49600) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use node --trace-deprecation ... to show where the warning was created)

Import trace for requested module: ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/compiler.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/script.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/main.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/index.js ./node_modules/.pnpm/degenerator@3.0.4/node_modules/degenerator/dist/src/index.js ./node_modules/.pnpm/pac-resolver@5.0.1/node_modules/pac-resolver/dist/index.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/agent.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/index.js ./node_modules/.pnpm/proxy-agent@5.0.0/node_modules/proxy-agent/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/utils/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/cloudinary.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/cloudinary.js ./app/shopify/page.tsx

./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/resolver-compat.js Critical dependency: the request of a dependency is an expression

Import trace for requested module: ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/resolver-compat.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/main.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/index.js ./node_modules/.pnpm/degenerator@3.0.4/node_modules/degenerator/dist/src/index.js ./node_modules/.pnpm/pac-resolver@5.0.1/node_modules/pac-resolver/dist/index.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/agent.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/index.js ./node_modules/.pnpm/proxy-agent@5.0.0/node_modules/proxy-agent/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/utils/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/cloudinary.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/cloudinary.js ./app/shopify/page.tsx

Import trace for requested module: ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/compiler.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/script.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/main.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/index.js ./node_modules/.pnpm/degenerator@3.0.4/node_modules/degenerator/dist/src/index.js ./node_modules/.pnpm/pac-resolver@5.0.1/node_modules/pac-resolver/dist/index.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/agent.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/index.js ./node_modules/.pnpm/proxy-agent@5.0.0/node_modules/proxy-agent/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/utils/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/cloudinary.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/cloudinary.js ./app/shopify/page.tsx

./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/resolver-compat.js Critical dependency: the request of a dependency is an expression

Import trace for requested module: ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/resolver-compat.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/main.js ./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/index.js ./node_modules/.pnpm/degenerator@3.0.4/node_modules/degenerator/dist/src/index.js ./node_modules/.pnpm/pac-resolver@5.0.1/node_modules/pac-resolver/dist/index.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/agent.js ./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/index.js ./node_modules/.pnpm/proxy-agent@5.0.0/node_modules/proxy-agent/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/utils/index.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/cloudinary.js ./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/cloudinary.js ./app/shopify/page.tsx

Hope this help Filippo

roberto-duran commented 1 year ago

Hi @spencersmb and @roberto-duran,

Thanks for reaching out.

In order to reproduce the issue, I need some more information. Can I please ask you to provide more details about the problem you're encountering?

I know that you're using next.js@13.4.4 and cloudinary@1.37.1 but can you please confirm your current node.js version?

Also what would really help me, would be some kind of a runnable snippet that breaks for you. I've set up a basic webpack (version 5.86.0) project with cloudinary@1.37.1 as a dependency and I'm not getting any similar errors to you. Also, the warnings mentioned by the OP are gone as well.

Looking forward to your response.

Best, Patryk Hi,

node V20.1.0

this is waht i try to run await cloudinary.v2.uploader.upload(image_url, { i also test it with the new cloudinary V1.37.2 and i have the same error that report @filipposwift oh btw im trying to run this in next.js routes api.

cloudinary-pkoniu commented 1 year ago

Hi @roberto-duran @filipposwift,

just wanted to let you know, that I managed to replicate the same behaviour with a new next.js project and I'm on it. I'll release the sdk that includes a fix as soon as possible.

Best, Patryk

ibqn commented 1 year ago

I am also affected by this, it seems that there is no possibility to use next 13 api routes together with with cloudinary node api.

- warn ./node_modules/.pnpm/coffee-script@1.12.7/node_modules/coffee-script/lib/coffee-script/coffee-script.js
require.extensions is not supported by webpack. Use a loader instead.

Import trace for requested module:
./node_modules/.pnpm/coffee-script@1.12.7/node_modules/coffee-script/lib/coffee-script/coffee-script.js
./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/compiler.js
./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/script.js
./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/lib/main.js
./node_modules/.pnpm/vm2@3.9.19/node_modules/vm2/index.js
./node_modules/.pnpm/degenerator@3.0.4/node_modules/degenerator/dist/src/index.js
./node_modules/.pnpm/pac-resolver@5.0.1/node_modules/pac-resolver/dist/index.js
./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/agent.js
./node_modules/.pnpm/pac-proxy-agent@5.0.0/node_modules/pac-proxy-agent/dist/index.js
./node_modules/.pnpm/proxy-agent@5.0.0/node_modules/proxy-agent/index.js
./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/utils/index.js
./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/lib-es5/cloudinary.js
./node_modules/.pnpm/cloudinary@1.37.2/node_modules/cloudinary/cloudinary.js
./src/app/api/sign-cloudinary-params/route.ts

./node_modules/.pnpm/coffee-script@1.12.7/node_modules/coffee-script/lib/coffee-script/coffee-script.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

is cloudinary also relying on the deprecated coffee-script package?

cloudinary-pkoniu commented 1 year ago

Hi @ibqn,

just wanted to answer your question regarding the coffee-script package. It's a dependency of a package vm2, which is a transitive dependency of proxy-agent that is listed in sdk's package.json as an optional dependency of the sdk.

By default, npm (not sure about the behaviour of yarn or pnpm though) installs all of the optional dependencies when using install command, unless an option --omit=optional is used. In my local env, when using next.js@13, installing project's dependencies with that option fixes the problem.

I understand it's only a quick workaround and not an actual fix, I'm trying to come up with an elegant solution that would fix all of the problems we've got listed here.

gmzi commented 1 year ago

Hi folks, just to add some more feedback about the dependecy warning, it happens only when cloudinary package is being used inside /app directory. The workaround I had to use was moving all cloudinary logic to /pages/api directory, and worked just fine in there. My versions: "cloudinary": "^1.37.1", "next": "13.4.2", Hope this helps and thanks for working on this

marketsystems commented 1 year ago

Hi folks, just to add some more feedback about the dependecy warning, it happens only when cloudinary package is being used inside /app directory. The workaround I had to use was moving all cloudinary logic to /pages/api directory, and worked just fine in there. My versions: "cloudinary": "^1.37.1", "next": "13.4.2", Hope this helps and thanks for working on this

Not a solution considering app dir is now stable and people probably want to use cloudinary with app dir without all the warnings :D

valenguerra commented 1 year ago

Please add support for Next.js 13.

ajesuscode commented 1 year ago

Same on my side

thatAwesomeKK commented 1 year ago

Still having the Problem

cloudinary-pkoniu commented 1 year ago

Hi everyone!

Please checkout the newest release, I removed the proxy-agent and replaced it with native https.Agent module. It should fix all your warnings and errors that you're experiencing.

Let me know if you're still running into issues, I'll do my best to assist.

Cheers, Patryk

roberto-duran commented 1 year ago

@cloudinary-pkoniu i just verify and it works!. in the next js server side, so no more work around needed. TY!

ibqn commented 1 year ago

@cloudinary-pkoniu thank you, works like a charm with app router.

thatAwesomeKK commented 1 year ago

Working Now, Just Tested! Thank You 🙂