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

Netlify Build Failing #12764

Closed
fanckush opened this issue Nov 10, 2021 · 36 comments
Closed

Netlify Build Failing #12764

fanckush opened this issue Nov 10, 2021 · 36 comments

Comments

@fanckush
Copy link

fanckush commented Nov 10, 2021

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

@danielroe
Copy link
Member

@fanckush See if you can set NODE_VERSION=16 (or 14.13.1+) in the environment variables configuration section.

@fanckush
Copy link
Author

fanckush commented Nov 10, 2021

@danielroe thanks for the quick reply,
I get the same error with both NODE_VERSION=16 as well as NODE_VERSION=14.16.0

the ENV is working as I see the following log:
3:45:10 PM: Now using node v14.16.0 (npm v6.14.11)

but the error is the same in both cases

@danielroe
Copy link
Member

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

@danielroe danielroe added upstream and removed nuxt3 labels Nov 10, 2021
@fanckush
Copy link
Author

Thanks! interestingly, in the logs Netlify says:

A Netlify Function failed to require one of its dependencies
Please make sure it is present in the site's top-level "package.json"

this makes it seem like it's on my end to add something

@danielroe
Copy link
Member

@fanckush My reading of the error message is that the script bundling the functions is expecting node:http (for example) to be a dependency, not realising that it is a node built-in.

@ascorbic
Copy link
Contributor

ascorbic commented Nov 10, 2021

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

@hrishikesh-k
Copy link

There's a related thread on Netlify Forums: https://answers.netlify.com/t/deploying-a-new-nuxt-3-app-result-to-error/47029

@netlify-team-account-1
Copy link

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

@netlify-team-account-1
Copy link

netlify-team-account-1 commented Nov 11, 2021

I was able to reproduce & fix this in netlify/zip-it-and-ship-it#802 🥳 Will ping here once it's deployed.

@pi0
Copy link
Member

pi0 commented Nov 11, 2021

Thanks for fix @netlify-team-account-1 <3

I'm wondering why netlify has to re-bundle nitro functions that are already made for Nelify? It is because you expect a CommonJS entrypoint? /cc @ascorbic

@ascorbic
Copy link
Contributor

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

@pi0
Copy link
Member

pi0 commented Nov 11, 2021

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 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?

@danielroe
Copy link
Member

danielroe commented Nov 11, 2021

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.

@productdevbook
Copy link
Sponsor Member

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

@ascorbic
Copy link
Contributor

ascorbic commented Nov 11, 2021

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).

@ascorbic
Copy link
Contributor

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.

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

@pi0
Copy link
Member

pi0 commented Nov 11, 2021

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.

@florian-lefebvre
Copy link
Contributor

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

I have the same right now, I'll use Vercel until this issue is resolved.

@ascorbic
Copy link
Contributor

@florian-lefebvre Did you just deploy that? The fix should have been live for a while now but it will need to be a new deploy before it will work.

@florian-lefebvre
Copy link
Contributor

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

@arnauddsj
Copy link

I confirm same problem here. Had the same error as the original post and now getting same error as florian-lefebvre on my site https://stoic-fermat-995d10.netlify.app/

image

@Thomasevano
Copy link

Thomasevano commented Nov 12, 2021

Hello, same issue here using nuxt 3
Capture d’écran 2021-11-12 à 01 31 10

@netlify-team-account-1
Copy link

Importing Node modules with the node: prefix was introduced in Node v14. The stacktraces seem like they're from Node v12, which is currently the default runtime on Netlify (probably going to be v14 soon). Please upgrade your deployment to v14 by setting the AWS_LAMBDA_JS_RUNTIME environment variable to nodejs14.x. This should resolve the error you're seeing.

@fanckush
Copy link
Author

fanckush commented Nov 12, 2021

So after the fix from @netlify-team-account-1 the deploy was succeeding! 🎉
But in the browser I was getting a runtime error like the others:

{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'node:http'\nRequire stack:\n- /var/task/.netlify/functions-internal/server/server.js\n- /var/task/server.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","trace":["Runtime.ImportModuleError: Error: Cannot find module 'node:http'","Require stack:","- /var/task/.netlify/functions-internal/server/server.js","- /var/task/server.js","- /var/runtime/UserFunction.js","- /var/runtime/index.js","    at _loadUserApp (/var/runtime/UserFunction.js:100:13)","    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","    at Object.<anonymous> (/var/runtime/index.js:43:30)","    at Module._compile (internal/modules/cjs/loader.js:999:30)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)","    at Module.load (internal/modules/cjs/loader.js:863:32)","    at Function.Module._load (internal/modules/cjs/loader.js:708:14)","    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)","    at internal/main/run_main_module.js:17:47"]}

Setting the following AWS ENV did not solve the issue (still getting the same runtime error):
image

EDIT: I've rebuild but forgot to mention in the original message

@netlify-team-account-1
Copy link

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

@leon0399
Copy link

@netlify-team-account-1 just tried to re-deploy my site with these envs, still same error
image

{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'node:http'\nRequire stack:\n- /var/task/.netlify/functions-internal/server/server.js\n- /var/task/server.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
  "trace": [
    "Runtime.ImportModuleError: Error: Cannot find module 'node:http'",
    "Require stack:",
    "- /var/task/.netlify/functions-internal/server/server.js",
    "- /var/task/server.js",
    "- /var/runtime/UserFunction.js",
    "- /var/runtime/index.js",
    "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
    "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:1072:14)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)",
    "    at Module.load (internal/modules/cjs/loader.js:937:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:778:12)",
    "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)",
    "    at internal/main/run_main_module.js:17:47"
  ]
}

@ascorbic
Copy link
Contributor

Thanks. That is very strange. We'll be looking into it today.

@ascorbic
Copy link
Contributor

It seems the frustrating answer is that the AWS Lambda runtime is currently on Node v14.17.4, while node: prefix support was introduced in Node 14.18! We're trying to think of a solution that's not "don't use node: prefixes"

@ascorbic
Copy link
Contributor

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.

@ascorbic
Copy link
Contributor

ascorbic commented Nov 12, 2021

OK, there already is an issue covering it: node-fetch/node-fetch#1367
We're looking into implementing the esbuild plugin solution. Thanks everyone for your patience!

@ascorbic
Copy link
Contributor

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.

@ascorbic
Copy link
Contributor

And, of course, should work for the regular lambda preset too

@netlify-team-account-1
Copy link

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

@productdevbook
Copy link
Sponsor Member

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

@florian-lefebvre
Copy link
Contributor

Fixed !

@fanckush
Copy link
Author

Works great!! The Manual ENV vars are not needed either! I was able to get it working out-of-the-box
I'll close the issue

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

No branches or pull requests