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

Fix ReferenceError: Headers is not defined #1768

Closed
wants to merge 2 commits into from

Conversation

cmeadows
Copy link

@cmeadows cmeadows commented Mar 7, 2024

Description

When locally Invoking functions via serverless-offline (cognito events, specifically), I received ReferenceError: Headers is not defined. This is being caused by the Fetch API Headers class and potentially missing polyfill for the API in my Node environment (specifically v20).

As such, I have added node-fetch to bring Fetch API compatibility.

Motivation and Context

When using serverless-offline and running local Invoke within a Python environment, I was getting the following error:

Debug: internal, implementation, error 
    ReferenceError: Headers is not defined
    at handler (file:///Users/collinmeadows/Development/myapp/node_modules/serverless-offline/src/lambda/routes/invocations/invocationsRoute.js:18:29)
    at exports.Manager.execute (/Users/collinmeadows/Development/myapp/node_modules/@hapi/hapi/lib/toolkit.js:57:29)
    at Object.internals.handler (/Users/collinmeadows/Development/myapp/node_modules/@hapi/hapi/lib/handler.js:46:48)
    at exports.execute (/Users/collinmeadows/Development/myapp/node_modules/@hapi/hapi/lib/handler.js:31:36)
    at Request._lifecycle (/Users/collinmeadows/Development/myapp/node_modules/@hapi/hapi/lib/request.js:370:68)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Request._execute (/Users/collinmeadows/Development/myapp/node_modules/@hapi/hapi/lib/request.js:280:9)

How Has This Been Tested?

I am actively running serverless-offline within multiple stacks. I made this change locally within node_modules/serverless-offline and re-invoked the function with no errors.

@DavidVaness
Copy link

DavidVaness commented Aug 7, 2024

fix would be nice, experiencing the same errors

@dherault
Copy link
Owner

Thanks. I did not merged your PR because it modifies the README heavily.
However I implemented your fix in the codebase. Published with v14.1.1

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

Successfully merging this pull request may close these issues.

3 participants