使用Serverless-offline本地测试AWS Lambda时出现node:url模块缺失错误
问题:Serverless-offline本地测试Lambda函数时提示找不到node:url模块
我在Node.js环境下使用Serverless Framework的serverless-offline插件本地测试AWS Lambda函数时遇到问题,无法执行简单的GET请求。目前可以通过serverless deploy命令成功部署到AWS Lambda,但为了提升团队开发体验,需要实现serverless-offline本地部署。
按配置指南操作后,成功运行serverless offline命令,但向http://localhost:3000/发送GET请求时,报错提示找不到node:url模块。即使已经执行npm install url,问题依然存在。
我的环境信息:
- Node.js版本:14.17.2
- 系统:MacOS Monterey(M1处理器)
以下是项目文件内容:
handler.js
//"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
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
{ "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" } }
内容的提问来源于stack exchange,提问作者Jorge Ortiz
相关产品推荐
相关产品推荐

