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

Cannot find module '@netlify/functions' #340

Open
lukasborawski opened this issue Apr 25, 2022 · 3 comments
Open

Cannot find module '@netlify/functions' #340

lukasborawski opened this issue Apr 25, 2022 · 3 comments
Labels
type: bug code to address defects in shipped code

Comments

@lukasborawski
Copy link

Hello. So I'm using scheduled functions and along with the dev env/mode it's working fine, I can serve it and invoke it. But as long I'm putting this to the server I have this error:

ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '@netlify/functions' ... 

The package is defined as a dependency in the package.json, and this is my function:

const { schedule } = require('@netlify/functions')

exports.handler = schedule('@hourly', async (event) => {
  const eventBody = JSON.parse(event.body)
  console.log(`Next function run at ${eventBody.next_run}.`)
  // function init
  return {
    statusCode: 200,
  }
})

Netlify config:

[build]
    functions = "functions"
     publish = "./"

[functions]
    directory = "functions/"
    external_node_modules = ["canvas", "jsdom"]

Functions are enabled on the Labs and Project page. What is wrong? Thanks for the help in advance.

@lukasborawski lukasborawski added the type: bug code to address defects in shipped code label Apr 25, 2022
@eduardoboucas
Copy link
Member

Hi @lukasborawski! I can't find anything obviously wrong with the code you shared, so I wonder if you could share a repository that we could use to reproduce the problem?

@lukasborawski
Copy link
Author

lukasborawski commented Apr 26, 2022

Hi @eduardoboucas So I've moved this function to the codebase, and even though I have some undefined errors.

[SyntaxError] - Unexpected end of JSON input

Locally it works fine. How can I debug this locally, and try it with the same environment as on the server? Or how to get some more detailed logs from the server?

@ghost
Copy link

ghost commented Oct 16, 2022

Just realized after I typed my answer that this issue is kind of old, but sharing anyway in case someone else wanders in here as I did.

You can use the netlify CLI to mimic your production environment locally and have a better chance of reproducing your issue locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

2 participants