-
Notifications
You must be signed in to change notification settings - Fork 114
Functions not being built and packaged? #142
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
Comments
We recently added support for unbundled function deployment to the buildbot and CLI (via https://github.com/netlify/zip-it-and-ship-it if you are curious). That means, you can deploy js functions with dependencies without bundling them first with a tool like netlify-lambda. Your deployed functions folder can contain function files that require modules in a node_modules in our outside the deployed functions folder. On deployment, we walk the dependency tree and grab all the dependencies the functions need. In general, it should work for bundled and unbundled functions. For some reason, its finding node-fetch requires an encoding module that appears to be consumed as a peer dependency (e.g. node-fetch requires it, but doesn't ship a reference in its package.json). The solution now is to install |
I'll open a tracking issue for |
hell is underspecified dependencies. |
That's actually pretty neat. I haven't messed with functions and So, in this case, I decided that rather than troubleshoot Unfortunately, I didn't get very far. First, I installed the CLI then ran
Which resulted in this: I removed the build command from my
As stated in the docs (and as you alluded to):
So It would seem, at this point, that I have the most basic setup you could have for deploying functions: I created a new function with
Am I missing something here? |
yea you caught us at the early stage where we still havent implemented package installing per function folder i think (@bcomnes knows, i dont work on that part). so basically right now the only way to do it is build locally and then |
Haha ok well, so I stopped using this "new" method and instead went back to the "old" way of doing things, which funnily enough is where I started when I first posted this issue. So to resolve the first issue I had, I added However, now my simple
But as soon as I try to bring in a fetch call, it fails.
That code results in Netlify functions logging this:
When I run
In fact, if I change that my
|
I'm experiencing the same |
No I haven’t been able to get this working. I basically gave up. Figured I’d try again later, or when somebody has some insight into the issue. |
I just had the same problem after using node-fetch inside a function, but for me installing |
thanks everyone for the feedback and sorry about these early troubles. i’m going to recommend people use axios for the time being. but also would love to fix the underlying problem |
Just to get the info out there, node-fetch uses an undeclared peer dependency in some cases. Our bundling tree shaker sometimes fails the build when it can't find this dependency. Failing the build due to missing dependencies is generally the desired behavior (vs a successful deploy that will fail during runtime due to missing deps), however in some cases, when modules do weird things, it's sometimes not what you want. We are currently investigating available options to handle this edge case in a cleaner manner. In the meantime, just install the |
This problem gets really nasty. I'm using googleapis, that has a nested dependency on node-fetch (from google-auth-library>gtoken>gaxios). Adding encoding to my own package.json doesn't affect the build as |
Argh! I wasted a couple hours reverting and rewriting various parts of my code... only then did I stumble upon this thread and discover that it was not my fault. Please try to be a little more careful when you make breaking changes! How am I supposed to know that I all I need to do is add "encoding" to my package.json? I've never even heard of that package before. |
I opened a PR to add a single exception for node-fetch oddness: |
@bcomnes - Nice - although I'm experiencing it with any of my "folder-style" functions (none of mine have node-fetch). I'm having to commit the function folder's node_modules folder with the git push in order for the function not to fail. |
The buildbot only automatically installs top level node_modules currently. If you have nested Additionally, you can also have a single top level package.json and node_modules shared between your site build and functions, and unbundled functions without their own package.json will use whatever is in there. This is probably the smoothest workflow for unbundled functions at the moment. In the PR mentioned above, we are experimenting with automatic package.json detection and |
Thank you @bcomnes! I figured this was the case (having to add a build step) but wasn't 100%. I wound up going with the classic netlify-lambda build step that I used to use. Only key difference I am noticing is that when serving functions with netlify-dev, the received POST request is base64 encoded and using netlify-lambda to serve does not. Not a big deal, just something I noticed. Thanks again for the detailed update! |
Sorry I posted the wrong PR: netlify/zip-it-and-ship-it#34 is the correct one that I intended to refer to. |
I was able to fix this temporarily by changing
to
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I never did see this fixed. My use case was pretty simple, so I ended up just removing my dependence on But it's unfortunate to see so many people had the same issue. Hopefully some of the workarounds listed in here help. |
looked like |
I was using |
Hello, any solution for that o is not a function? |
I've been trying to get a simple set of functions setup and running and it keeps failing and I can't figure out why.
My
netlify.toml
looks like this:And my
npm run build
command is justnetlify-lambda build src
If I run
npm run build
locally, everything works just fine.But as soon as I push, the build fails:
This is the interesting line to me: "Could not find "encoding" module in file: /repo/dist/icg-slack-deploy.js."
What's interesting is that I am only
require
ing one dependency in that file:That line of code is making everything fail. If I comment that file out, Netlify builds everything as expected (but then the function doesn't work, because I can't use
fetch
).Am I missing something here?
The text was updated successfully, but these errors were encountered: