You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 15:26:06