The JS version of my project's Cypress config has
const cucumber = require('cypress-cucumber-preprocessor').default;
This works fine. But I thought the import
equivalent should be
import cucumber from 'cypress-cucumber-preprocessor';
and this results in
TypeError: (0 , cypress_cucumber_preprocessor_1.default) is not a function
Looking at the module's code I see it exports like this:
const preprocessor = <an arrow function>
module.exports = {
default: preprocessor,
transform,
};
In my tsconfig.json
I have
"module": "commonjs",
"esModuleInterop": true,
I found two workarounds which work, but I don't like either:
Option 1:
import cucumber_ from 'cypress-cucumber-preprocessor';
const cucumber = cucumber_.default;
which doesn't pass TS typechecking, it thinks cucumber_
is the default exported function.
Option 2: keep the old version with a type assertion
const cucumber = require('cypress-cucumber-preprocessor').default as (options?: any) => (file: any) => Promise<string>;
What am I missing?