nuxt: Netlify Build Failing

Environment

  • Operating System: Darwin
  • Node Version: v14.18.1
  • Nuxt Version: 0.0.0
  • Package Manager: yarn@1.22.10
  • Bundler: Webpack
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Describe the bug

Am I doing something wrong?

Netlify Deploy is failing

1:48:13 PM:   2. Functions bundling                                         
1:48:13 PM: ────────────────────────────────────────────────────────────────
1:48:13 PM: ​
1:48:13 PM: Packaging Functions from .netlify/functions-internal directory:
1:48:13 PM:  - server/server.ts
1:48:13 PM: ​
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/index.js:9:17: error: Could not resolve "node:http" (mark it as external to exclude it from the bundle)
1:48:13 PM:     9 │ import http from 'node:http';
1:48:13 PM:       ╵                  ~~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/index.js:10:18: error: Could not resolve "node:https" (mark it as external to exclude it from the bundle)
1:48:13 PM:     10 │ import https from 'node:https';
1:48:13 PM:        ╵                   ~~~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/index.js:11:17: error: Could not resolve "node:zlib" (mark it as external to exclude it from the bundle)
1:48:13 PM:     11 │ import zlib from 'node:zlib';
1:48:13 PM:        ╵                  ~~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/index.js:12:52: error: Could not resolve "node:stream" (mark it as external to exclude it from the bundle)
1:48:13 PM:     12 │ import Stream, {PassThrough, pipeline as pump} from 'node:stream';
1:48:13 PM:        ╵                                                     ~~~~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/body.js:8:34: error: Could not resolve "node:stream" (mark it as external to exclude it from the bundle)
1:48:13 PM:     8 │ import Stream, {PassThrough} from 'node:stream';
1:48:13 PM:       ╵                                   ~~~~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/body.js:9:31: error: Could not resolve "node:util" (mark it as external to exclude it from the bundle)
1:48:13 PM:     9 │ import {types, deprecate} from 'node:util';
1:48:13 PM:       ╵                                ~~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/request.js:10:34: error: Could not resolve "node:url" (mark it as external to exclude it from the bundle)
1:48:13 PM:     10 │ import {format as formatUrl} from 'node:url';
1:48:13 PM:        ╵                                   ~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/headers.js:7:20: error: Could not resolve "node:util" (mark it as external to exclude it from the bundle)
1:48:13 PM:     7 │ import {types} from 'node:util';
1:48:13 PM:       ╵                     ~~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/node-fetch/src/headers.js:8:17: error: Could not resolve "node:http" (mark it as external to exclude it from the bundle)
1:48:13 PM:     8 │ import http from 'node:http';
1:48:13 PM:       ╵                  ~~~~~~~~~~~
1:48:13 PM:  > .netlify/functions-internal/server/node_modules/fetch-blob/from.js:1:59: error: Could not resolve "node:fs" (mark it as external to exclude it from the bundle)
1:48:13 PM:     1 │ import { statSync, createReadStream, promises as fs } from 'node:fs'
1:48:13 PM:       ╵                                                            ~~~~~~~~~
1:48:13 PM: 10 of 12 errors shown (disable the message limit with --log-limit=0)
1:48:13 PM: ​
1:48:13 PM: ────────────────────────────────────────────────────────────────
1:48:13 PM:   Dependencies installation error                               
1:48:13 PM: ────────────────────────────────────────────────────────────────
1:48:13 PM: ​

Reproduction

Additional context

No response

Logs

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 36 (23 by maintainers)

Most upvoted comments

I deployed https://github.com/netlify/zip-it-and-ship-it/pull/806 to production. The issue should not occur anymore. If it does, please let me know 😃

I deployed netlify/zip-it-and-ship-it#806 to production. The issue should not occur anymore. If it does, please let me know 😃

fixed thank you

This seems like a regression related to a change I introduced into Netlify’s bundling process. Looking into it!

I think it just might be possible to emit the right kind of entrypoint (while keeping the rest of the lambda ESM). There are some examples out there of people who’ve done the same with AWS Lambda, e.g. here.

Separately, @danielroe: I’ve confirmed that this should work for us too, and would mean it woudln’t be re-bundled.

It’s node-fetch that’s the problem: they claim to support Node 12, but in the latest release changed all the imports to use the prefix. I’m going to open an issue.

Would this give any benefit aside from consistency in compiling most targets to ESM?

Yes! Most importantly for dealing with esm-only packages. If we output CJS format should bundle all or some of the externals as well losing benefit of vercel/nft.

I was kinda assuming Netlify does dark magic for supporting ESM with lambda till today 😆 But of course we can update netlify preset to emit CJS (or CJS entry). We need it for generic AWS support anyway. BTW may I ask how it works? If the function is using .js netlify won’t use esbuild or there is a specific configuration to specify not building?

@pi0 That does sound like the simplest solution. Changing it to .js should just work: it will switch back to the default bundler, which doesn’t compile anything. I made the entrypoint .ts because at the time that was the simplest way to switch the bundler into esbuild mode without needing to add any config (now .mjs will do the same).

Environment


  • Operating System: Darwin
  • Node Version: v16.13.0
  • Nuxt Version: 3.0.0-27277330.202617b
  • Package Manager: yarn@1.22.15
  • Bundler: Vite
  • User Config: buildModules, build
  • Runtime Modules: -
  • Build Modules: @pinia/nuxt@0.1.5

Describe the bug

https://v3nuxt.netlify.app

CleanShot 2021-11-11 at 17 33 30@2x

Reproduction

https://github.com/productdevbook/nuxt3-app

Additional context

No response

Logs

No response

Updated env vars only go into effect on new deploys, did you redeploy your site?

It still doesn’t work. I just deployed it, here is the link https://youthful-gates-3fd198.netlify.app/.

I think it just might be possible to emit the right kind of entrypoint (while keeping the rest of the lambda ESM). There are some examples out there of people who’ve done the same with AWS Lambda, e.g. here.

Correct. AWS lambda doesn’t support ESM, so we need to transpile it all. If Nitro can generate a node 14 -compatible cjs bundle then it could run it unchanged

I was able to reproduce & fix this in https://github.com/netlify/zip-it-and-ship-it/pull/802 🥳 Will ping here once it’s deployed.

Hey. This certainly seems to be a bundling issue. The node:-prefix import issue came up before, but I thought we had fixed it. Tagging @eduardoboucas to see if he has any insight

Then I think this should be raised upstream with Netlify as it’s happening not within the Nuxt build step but within packaging functions.

cc: @ascorbic