dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

Typescript stopped working when upgrades. #87

Closed carlitux closed 4 years ago

carlitux commented 5 years ago
src/proxy.ts:4:29 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.

4 import * as serverless from 'serverless-http';
                              ~~~~~~~~~~~~~~~~~
dougmoscrop commented 5 years ago

I don't use TypeScript, maybe someone who contributed the ts definitions can chime in - @awwong1 / @tomc974 (was it this change -- https://github.com/dougmoscrop/serverless-http/commit/d15fc767690b9cb853549854baf2001d5fd6462a#diff-2dfb4ffe9905581b8cba9e8ef3fed4fb ?)

tomc974 commented 5 years ago

Hi!

The change I made was to fix the export of the module to be a function. The TypeScript definitions was not in agreement with the actual code on this matter.

The proper way to import such a module (which is not ECMAScript compatible) is to use a different kind of import statement

import serverless = require('serverless-http')

Alternatively, you can enable the esModuleInterop compiler setting if you still want to use ECMAScript import with incompatible modules.

Let me know if this solve your issue.

grath90 commented 5 years ago

I'm having the same issue even after enabling the "esModuleInterop" flag in tsconfig

tomc974 commented 5 years ago

@grath90 Could you try with the non-ECMAScript import syntax and tell me if the problem remains?

grath90 commented 5 years ago

@tomc974 I imported with a standard node require and the error went away. Which is fine for me, but I am curious why enabling the flag didn't fix it.

dougmoscrop commented 5 years ago

Flagged as help wanted since I don't use TS - if someone can help me understand if this needs changes or is fixed that would be great.

shellscape commented 4 years ago

FWIW this has regressed again, if #126 fixed this issue at a point in time.