opennextjs / opennextjs-netlify

Open Next.js adapter for Netlify
https://opennext.js.org/netlify
677 stars 86 forks source link

[Bug]: A Netlify Function failed to require one of its dependencies. #884

Closed monsieurnebo closed 2 years ago

monsieurnebo commented 2 years ago

Steps to reproduce

I'm facing the following error on my Netlify Build: A Netlify Function failed to require one of its dependencies.

It seems related to my dependencies update commit.

A link to a reproduction repository

https://github.com/monsieurnebo/website-etchebades/

Plugin version

3.9.2

More information about your build

What OS are you using?

Mac OS

Your netlify.toml file

`netlify.toml` ```toml # Paste content of your `netlify.toml` file here ```

Relevant log output (or link to your logs)

Build logs ``` 7:49:29 PM: ──────────────────────────────────────────────────────────────── 7:49:29 PM: 4. Functions bundling 7:49:29 PM: ──────────────────────────────────────────────────────────────── 7:49:29 PM: ​ 7:49:29 PM: Packaging Functions from .netlify/functions-internal directory: 7:49:29 PM: - next_api_quotes/next_api_quotes.js 7:49:29 PM: - next_api_randomQuote/next_api_randomQuote.js 7:49:29 PM: - next_citations_index/next_citations_index.js 7:49:29 PM: - next_image/next_image.js 7:49:31 PM: ──────────────────────────────────────────────────────────────── 7:49:31 PM: Dependencies installation error 7:49:31 PM: ──────────────────────────────────────────────────────────────── 7:49:31 PM: ​ 7:49:31 PM: Error message 7:49:31 PM: A Netlify Function failed to require one of its dependencies. 7:49:31 PM: Please make sure it is present in the site's top-level "package.json". ​ 7:49:31 PM: In file "/opt/build/repo/.netlify/functions-internal/next_citations_index/next_citations_index.js" 7:49:31 PM: Cannot find module '../../webpack-runtime.js' from '/opt/build/repo/.netlify/functions-internal/next_citations_index/nextPage/pages/citations' 7:49:31 PM: ​ 7:49:31 PM: Resolved config 7:49:31 PM: build: 7:49:31 PM: command: npm run build 7:49:31 PM: commandOrigin: ui 7:49:31 PM: publish: /opt/build/repo/dist 7:49:31 PM: publishOrigin: ui 7:49:31 PM: functions: 7:49:31 PM: '*': 7:49:31 PM: included_files: 7:49:31 PM: - '!node_modules/@next/swc-*/**/*' 7:49:31 PM: - '!node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*' 7:49:31 PM: headers: 7:49:34 PM: - for: /_next/static/chunks/* values: cache-control: public, max-age=31536000, immutable plugins: - inputs: {} origin: ui package: '@netlify/plugin-nextjs' ```
ascorbic commented 2 years ago

Hi, Can you try installing the beta to see if that helps?

hakimmazouz commented 2 years ago

@monsieurnebo Adding the following to my netlify.toml helped, can't remember where I saw it.

[functions]
  # Specifies `esbuild` for functions bundling
  node_bundler = "esbuild"
  external_node_modules = ["next", "@ampproject/toolbox-optimizer", "sharp"]
gui-santos commented 2 years ago

Hi!

I'm having the same problem and in my case I'm using a monorepo that has two different websites being deployed with Netlify. One is a Next.js site and the other is a Gatsby website If I don't use netlify-plugin-nextjs, my nextjs website fails to deploy If I use netlify-plugin-nextjs (the beta version), my nextjs website deploys successfully but my Gatsby website fails because Netlify tries to use the plugin on it as well

I need to make netlify use the configurations in netlify.toml file only for the next.js website Do you have any ideas?

ascorbic commented 2 years ago

@gui-santos Hey. Can you put separate toml files in the root of the Next.js and Gatsby site, and set the individual base path to each site rather than having one in the root?

gui-santos commented 2 years ago

@gui-santos Hey. Can you put separate toml files in the root of the Next.js and Gatsby site, and set the individual base path to each site rather than having one in the root?

@ascorbic oh! I didn't try that, let me check

I have a feeling I can't because this monorepo has other packages and they all need to be built So we are basically building everything from the root and then going into the website folder and getting the files /build /.next

anyway, thanks for the hint I will check it right now 🙇

ascorbic commented 2 years ago

Depending on your monorepo setup that may still work. Here are some docs on monorepo setup. Generally a Yarn workspace works most smoothly, because running yarn in any package will bootstrap the whole thing.

gui-santos commented 2 years ago

Depending on your monorepo setup that may still work. Here are some docs on monorepo setup. Generally a Yarn workspace works most smoothly, because running yarn in any package will bootstrap the whole thing.

@ascorbic IT WORKED! You're the best

ascorbic commented 2 years ago

Fantastic! That's great news. Thanks for letting me know.

ascorbic commented 2 years ago

Hi @monsieurnebo Did oyu ever manage to try this with version 4 of the plugin? It is now out of beta, and should hopefully fix this.

monsieurnebo commented 2 years ago

Hi guys,

Thanks for your answers. I will try this as soon as possible & come back to you.

monsieurnebo commented 2 years ago

I upgrade the Netlify Next plugin to v4 (through the UI) and it fixed the issue.

Thanks for the help guys 👌