serverless-http icon indicating copy to clipboard operation
serverless-http copied to clipboard

"Error Cannot find module"

Open jona164q opened this issue 4 years ago • 4 comments

Hi, i cant install external dependencies on my project. i have tried using a "node_modules" folder and a "package.json" without success. i have been in contact with your support and we decided to "ask" here.

my simple code is: " const serverless = require('serverless-http'); const express = require('express') const got = require("got") const app = express()

app.get('/', async function (req, res) { const headers = { "Connection": "keep-alive", "sec-ch-ua": '"Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"', "sec-ch-ua-mobile": "?0", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36", "Content-Type": "text/plain;charset=UTF-8", "Sec-Fetch-Site": "same-origin", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Dest": "empty", "Accept-Encoding": "gzip, deflate, br", }

const options = {
    method: "get",
    headers: headers,
    url: 'https://www.google.com/',
}

const hej = await got(options)
res.send(hej)

})

module.exports.handler = serverless(app); "

my serverless.yml is looking like this: " org: jona164q app: api service: my-express-application

provider: name: aws runtime: nodejs14.x stage: dev region: eu-central-1

functions: app: handler: index.handler events: - http: ANY / - http: 'ANY {proxy+}' "

jona164q avatar Oct 25 '21 17:10 jona164q

Hmm, I am not quite sure how this would be a problem with this library - but I'm happy to try and help, are you able to push an example to a repository so I can see everything? If not, what does package.json look like?

dougmoscrop avatar Oct 26 '21 04:10 dougmoscrop

i created a simple test repository here, please do npm install when you have it downloaded, as i couldn't add all the node_modules files - https://github.com/jona164q/serverless-test

jona164q avatar Oct 26 '21 18:10 jona164q

Got it - yeah, you need to include serverless-http and express in your package.json, right now you only have got : https://github.com/jona164q/serverless-test/blob/main/package.json#L8

dougmoscrop avatar Oct 26 '21 20:10 dougmoscrop

hey. i did that but still getting errors when importing got. i updated the repo if you want to have a look

jona164q avatar Oct 27 '21 08:10 jona164q