__filename throwing a reference error when using Rollup’s typescript plugin in an AWS Lambda

I’ve been battling this for a while now. I have an AWS Lambda which is running the rollup bundler in an AWS Lambda function, and uses the typescript plugin but it throws a an error:

ReferenceError: __filename is not defined in ES module scope

which is being thrown from the typescript module itself:

at isFileSystemCaseSensitive (/.../node_modules/typescript/lib/typescript.js:6361:41)

I’ve tried all sorts of different configurations to make this work, but I continue to get this error. I feel like at this point I must have a fundamental misunderstanding about something. My current compiler options are:

 "compilerOptions": {
    "module": "CommonJS",
    "moduleResolution": "node",
    "target": "ES6"
  }

but I’ve tried seemingly every other module and target under then sun.

What am I doing wrong?

Leave a Comment