vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.07k stars 27k forks source link

`cache: 'no-store'` does not prevent `fetch` during static build #59751

Open xixixao opened 11 months ago

xixixao commented 11 months ago

Link to the code that reproduces this issue

https://github.com/xixixao/nextjs-cache-no-store

To Reproduce

  1. npm run build

Current vs. Expected behavior

What I expect

I expect to get no warnings. I specifically expect to not make a fetch during static build which has cache: 'no-store' set. This is important because I might be making a push in this sequence:

  1. Build my site
  2. Deploy my external API service
  3. Deploy my site

What I get

The fetch still executes during the static build:

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11600:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error: getaddrinfo ENOTFOUND does.not.exist.foo.bar.boom
      at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26)
      at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'does.not.exist.foo.bar.boom'
  }
}

This might cause errors on my external API service because the new static build might run an API that the my external service isn't supporting yet.

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
Binaries:
  Node: 20.6.1
  npm: 10.1.0
  Yarn: N/A
  pnpm: 8.7.4
Relevant Packages:
  next: 14.0.5-canary.18
  eslint-config-next: 14.0.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Data fetching (gS(S)P, getInitialProps)

Additional context

It seems that in the past this kind of error actually failed the build and that's no longer the case, which is good.

xixixao commented 11 months ago

Another reason this is problematic is that this warning can fail a strict build script which doesn't allow warnings.

landg16 commented 9 months ago

Is there any update on this? I'm facing the same issue.

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!