首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无服务器框架- get请求上的脱机启动错误无法找到模块‘节点:url’(Lambda AWS)

无服务器框架- get请求上的脱机启动错误无法找到模块‘节点:url’(Lambda AWS)
EN

Stack Overflow用户
提问于 2022-09-23 00:42:54
回答 2查看 506关注 0票数 3

我有以下问题..。结果,我无法在无服务器的nodejs框架中的无服务器离线插件上测试我的aws lambda函数。无法执行简单的GET请求。

我能够使用serverless deploy命令部署到aws,但是为了更好地使用无服务器脱机部署团队的开发经验,我遵循了这个指南https://fauna.com/blog/develop-using-serverless-offline,但在成功运行serverless offline命令之后执行简单的get请求时却陷入了困境。这是在成功运行serverless offline时得到的。

但是,当我通过postman向链接http://localhost:3000/发出get请求时,我会得到以下错误

它基本上说找不到节点:url模块,但我做了npm安装url,但仍然抛出相同的错误。我将在下面插入项目树和文件:

handler.js

代码语言:javascript
复制
//"use strict";

console.log("AJAJAJAJAJAJAJAJAJAAJAJ");

console.log("Printing module");
console.log(module.exports);

module.exports.hello = async (event) => {
  console.log("whaaaaat");
  return {
    statusCode: 200,
    body: JSON.stringify(
      {
        message: "Go Serverless v3.0! Your function executed successfully!",
        input: event,
      },
      null,
      2
    ),
  };
};

serverless.yml

代码语言:javascript
复制
org: ortizjorge97
app: aws-node-http-api-project
service: aws-node-http-api-project
frameworkVersion: '3'

provider:
  name: aws
  runtime: nodejs14.x

plugins:
  - serverless-offline
  - serverless-bundle
  - serverless-dotenv-plugin

functions:
  hello:
    handler: handler.hello
    events:
      - httpApi:
          path: /
          method: get

package.json

代码语言:javascript
复制
{
  "name": "aws-node-http-api-project",
  "version": "1.0.0",
  "description": "<!-- title: 'AWS Simple HTTP Endpoint example in NodeJS' description: 'This template demonstrates how to make a simple HTTP API with Node.js running on AWS Lambda and API Gateway using the Serverless Framework.' layout: Doc framework: v3 platform: AWS language: nodeJS authorLink: 'https://github.com/serverless' authorName: 'Serverless, inc.' authorAvatar: 'https://avatars1.githubusercontent.com/u/13742415?s=200&v=4' -->",
  "main": "handler.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "serverless-bundle": "^5.5.0",
    "serverless-dotenv-plugin": "^4.0.2",
    "url": "^0.11.0"
  },
  "devDependencies": {
    "serverless-offline": "^10.2.0"
  }
}

我是aws的新手,所以我不知道会发生什么。

我在用

  • 节点14.17.2
  • MacOS蒙特利m1处理器
EN

回答 2

Stack Overflow用户

发布于 2022-10-15 11:57:05

您需要将实际的无服务器包本身安装为一个dev依赖项。试试这个:

npm i -D serverless

注意到:记得检查无服务器离线的文档,以了解找到支持的无服务器包版本。

票数 0
EN

Stack Overflow用户

发布于 2022-11-22 07:43:29

我输入了太节点14.17.3,框架3.25.0 (本地),插件6.2.2,SDK 4.3.2

我可以通过在UserFunction.js中导入所需的更改来解决修复问题

img.png

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73821950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档