Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alert message during build "require function is used in a way in which dependencies cannot be statically extracted" #273

Open
jbilcke-hf opened this issue Jun 22, 2024 · 8 comments

Comments

@jbilcke-hf
Copy link

jbilcke-hf commented Jun 22, 2024

Hello, for your information I get this message when I use the library in a Next project (replicate 0.30.2 with Next 14.2.3 or Next 14.2.4 - I haven't tested older combinations):

 ⚠ Compiled with warnings

./node_modules/replicate/lib/util.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
./node_modules/replicate/lib/util.js
./node_modules/replicate/index.js

I don't know exactly the consequences, my Next app seems to work just fine despite the scary "critical dependency" message, but you might still wanna check it out as other people might come across this too.

For a bit more context, I'm using a lot (90+) of other modules in the same project like langchain etc (I hope we will see a @langchain/replicate NPM module soon by the way) but none of them trigger this, so that's weird.

I'm using replicate on server-side not client-side (ie. I'm using it for Next's API endpoints) so it runs in a Node environment.

The tsconfig.json is like this if that can help:

{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}
@mattt
Copy link
Contributor

mattt commented Jun 22, 2024

Hi @jbilcke-hf. Thanks for writing in. I believe that warning relates to this code which dynamically requires node:crypto as needed.

Is your project is using Webpack or Turbopack? Can you share any other details of you Next configuration?

@jbilcke-hf
Copy link
Author

jbilcke-hf commented Jun 24, 2024

I am using Webpack, here is my project for reference: @jbilcke-hf/clapper (note: this is a work in progress so some things like the support for Replicate are not 100% finished yet)

I've just tried to create a minimal Next project to try to reproduce the issue but I wasn’t able to (a bare Next project + Replicate module doesn't trigger this warning)

Since this seems caused by a weirdness in my project, like a dependency trying to polyfill require(), I'm sorry for taking your time on this. This is probably not worth looking too much into.

@aron
Copy link
Contributor

aron commented Jul 5, 2024

The node protocol is supported now in Webpack 5.92.0. I wonder what the upgrade curve is for Webpack in Next projects… it would be nice to remove the code...

@danny-hunt
Copy link

Hey, I'm experiencing this too in a nextjs project where I want to use replicate server-side. It's quite annoying! I've overridden the default console behaviour on local to avoid getting spammed during dev too much. When I have more time I might back and try to remove the replicate sdk in favour of using the api instead.

My ssr configuration is a bit janky so it could be my fault. But if there's any ideas for a work-around to just suppress these alert messages then that would be amazing!

@mattt
Copy link
Contributor

mattt commented Jul 24, 2024

Hi @danny-hunt. Sorry for all the noise. You should be able to suppress this by adding the following to your webpack.config.{js,ts} file:

ignoreWarnings: [
+   {
+     module: /replicate/,
+     message: /require function is used in a way in which dependencies cannot be statically extracted/,
+   },
]

@danny-hunt
Copy link

@mattt Thanks so much! Worked a charm & I learned something new today 😄

@farezv
Copy link

farezv commented Sep 24, 2024

Anyone using turborepo + bun combo also getting this? It's funny I don't get any issues when deploying my Next.js app to Vercel but to self host deploy it via coolify or trying to write a Dockerfile for it and I'm getting this error.

37.41 ../../node_modules/replicate/lib/util.js
37.41 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
37.41 
37.41 Import trace for requested module:
37.41 ../../node_modules/replicate/lib/util.js
37.41 ../../node_modules/replicate/index.js
37.41 ../../packages/replicate/createReplicateClient.ts

@christian-ek
Copy link

Am getting spammed with this in turborepo, how can I suppress the warnings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants