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

TypeError: (0 , serverless_express_1.configure) is not a function

Open nekman opened this issue 4 years ago • 2 comments

Using version @vendia/serverless-express: 4.5.2

Trying to import the "serverlessExpress" module and do something similar as described here: https://github.com/vendia/serverless-express/blob/mainline/examples/basic-starter-api-gateway-v2/src/lambda-async-setup.js

but, in a TypeScript project.

import logger from 'src/logger';
import ConfigurationProvider from 'src/ConfigurationProvider';
import { configure as serverlessExpress } from '@vendia/serverless-express';
import { APIGatewayEvent, Context } from 'aws-lambda';

let serverlessInstance;

/**
 * See https://github.com/vendia/serverless-express/blob/5c1e0a59e9fdce03cbba3912ba33de8dd9773348/README.md#async-setup-lambda-handler
 */
async function setup(event: APIGatewayEvent, context: Context, configProvider = new ConfigurationProvider()) {
  // Loads the configuration from SSM.
  await configProvider.loadAppConfig();

  const app = (await import('src/app')).default;

  serverlessInstance = serverlessExpress({ app: app() });
  serverlessInstance(event, context);
}

/**
 */
export function handler(event: APIGatewayEvent, context: Context) {
  if (serverlessInstance) {
    return serverlessInstance(event, context);
  }

  return setup(event, context).catch(err => {
    logger.error('Could not start app!', err);
  });
}

This is my tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "module": "commonjs",
    "outDir": "./dist",
    "noImplicitAny": false,
    "sourceMap": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "jsx": "react",
    "lib": ["es2020", "dom"],
    "target": "es2019",
    "baseUrl": ".",
    "plugins": [
      { "transform": "ts-transformer-imports" }
    ]
  }

Tried to import both with:

import serverlessExpress from '@vendia/serverless-express';

And

import { configure as serverlessExpress } from '@vendia/serverless-express';

Can't get it to work. Always get the following error:

TypeError: (0 , serverless_express_1.configure) is not a function

Or:

TypeError: (0 , serverless_express_1.default) is not a function

nekman avatar Oct 26 '21 09:10 nekman

I was able to fix it by adding "esModuleInterop": true, to my tsconfig.json. Maybe this helps you too?

flogy avatar Oct 30 '21 14:10 flogy

Adding "esModuleInterop": true to my tsconfig.json did not work for me. Is there another issue here?

robblovell avatar Nov 17 '22 16:11 robblovell