When encountering a zip file, ignore it and show a log message that we haven't loaded the function
outerlook opened this issue · 5 comments
- Do you want to request a feature or report a bug?
Bug
- What is the current behavior?
I've being trying to get along small functions to understand netlify functions, etc
I try to first build the functions then use netlify dev command netlify functions:serve
.
But right now after trying a really simple function test.ts
I get this error
◈ Loaded function test.
◈ Functions server is listening on 9999
◈ Failed reloading function test with error:
Cannot read property 'filter' of undefined
at buildFunction (C:\Users\RaffaelCampos\AppData\Roaming\npm\pnpm-global\5\node_modules.pnpm\netlify-cli@6.8.1\node_modules\netlify-cli\src\lib\functions\runtimes\js\builders\zisi.js:42:27)
at NetlifyFunction.build (C:\Users\RaffaelCampos\AppData\Roaming\npm\pnpm-global\5\node_modules.pnpm\netlify-cli@6.8.1\node_modules\netlify-cli\src\lib\functions\netlify-function.js:53:42)
at FunctionsRegistry.buildFunctionAndWatchFiles (C:\Users\RaffaelCampos\AppData\Roaming\npm\pnpm-global\5\node_modules.pnpm\netlify-cli@6.8.1\node_modules\netlify-cli\src\lib\functions\registry.js:73:37)
- If the current behavior is a bug, please provide the steps to reproduce.
// zipItAndShipIt config used to build
const archive = await zipFunctions("src/lambda", "dist", {
archiveFormat: "zip",
config: {
nodeVersion: "14.x",
nodeBundler: "esbuild"
}
});
// test.ts
import { Handler } from "@netlify/functions";
const handler: Handler = async (event, context) => {
return {
statusCode: 200,
body: "Hello, World",
};
};
export { handler };
1 - build with ZipItAndShipIt
2 - netlify functions:serve
- What is the expected behavior?
Be able to get "Hello world" while acessing http://localhost:9999/.netlify/functions/teste
- Please mention your node.js, and operating system version.
Node 14
Windows 10
PNPM as package manager
"@netlify/functions": "0.7.2",
"@netlify/zip-it-and-ship-it": "4.20.0",
netlify-cli installed globally 6.8.1
the line that errors undefined
:
https://github.com/netlify/cli/blob/388bc795e9b171907fe28ace7cc0c7377c381543/src/lib/functions/runtimes/js/builders/zisi.js#L42
Here is a reproduction repository:
https://github.com/outerlook/netlify-function-test
Sorry, I misunderstood functions:serve
capabilities. I thought it could handle .zip
as it correctly copies these files. But when I unzip before running it goes smoothly.
Thanks for creating this, @outerlook! I'm glad you're unblocked, but I've reopened the issue because it feels like we should address this use case better. The error message you saw is cryptic and not very helpful.
@eduardoboucas and @minivan, I think this issue should be reopened under netlify/cli since it's related to the CLI registry module. I implemented a fix here https://github.com/karagulamos/cli/blob/fix/function-serve-ignore-zip-file/src/lib/functions/registry.js#L146 and am ready to do a PR.
thanks @karagulamos for adding the error message! We'll consider this one solved then