Bug Report
Current Behavior
When running serverless-offline in Node 22, and now Node 20.19, there is a startup error.
import { Server } from "@hapi/hapi"
^^^^^^
SyntaxError: Named export 'Server' not found. The requested module '@hapi/hapi' is a CommonJS module, which may not support all module.exports as named exports.
Sample Code
Running a basic serverless setup with a lambda function should trigger the issue.
service: my-service
plugins:
- serverless-offline
provider:
runtime: nodejs18.x
stage: dev
functions:
hello:
events:
- http:
method: get
path: hello
handler: handler.hello
"use strict"
const { stringify } = JSON
exports.hello = async function hello() {
return {
body: stringify({ foo: "bar" }),
statusCode: 200,
}
}
Expected behavior/code
Environment
serverless version: 3.40
serverless-offline version: 14.4
node.js version: 20.19 or 22.x
OS: macOS
Possible Solution
import hapi from "@hapi/hapi"
const { Server } = hapi;
Also, fs-extra, jsonschema, aws-lambda-ric/UserFunction.js. and possibly other commonjs packages that are not triggered by our code.
Additional context/Screenshots
The issue can be avoided by not upgrading node versions, or potentially engaging available node experimental flags, but updating the code to follow the now prescribed import-of-commonjs syntax seems appropriate.
Bug Report
Current Behavior
When running serverless-offline in Node 22, and now Node 20.19, there is a startup error.
Sample Code
Running a basic serverless setup with a lambda function should trigger the issue.
Expected behavior/code
Environment
serverlessversion: 3.40serverless-offlineversion: 14.4node.jsversion: 20.19 or 22.xOS: macOSPossible Solution
Also, fs-extra, jsonschema, aws-lambda-ric/UserFunction.js. and possibly other commonjs packages that are not triggered by our code.
Additional context/Screenshots
The issue can be avoided by not upgrading node versions, or potentially engaging available node experimental flags, but updating the code to follow the now prescribed import-of-commonjs syntax seems appropriate.