helmetjs/nocache

Upgrading nocache to 3.0.2 breaks compilation for a Typescript/commonjs project

danzGentrack opened this issue · 2 comments

My typescript project imports nocache like this.
import * as nocache from "nocache";

This worked fine until I upgraded the dependency to the version 3.0.2. I got the following error now:

error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.

It is a typescript project with tsconfig.json like this:

...
    "compilerOptions": {
        "noImplicitAny": true,
        "target": "ES2020",
        "module": "commonjs",
        "watch": false,
        "sourceMap": true,
        "strict": true,
        "useUnknownInCatchVariables": false
    },
...

Sorry about this. I'll take a look.

In the short term, you can downgrade to 3.0.1 to avoid this problem.

tl;dr: this should be fixed in nocache@3.0.3, out now.

Note that the kind of import you're using is incorrect. This kind of code should not work:

// This should not work:
import * as foo from 'my-example-import';
foo();

That's because import * imports the whole package as a namespace. TypeScript sometimes lets you get away with this, but it's not technically valid JavaScript as far as I understand.

Again, this should be fixed in nocache@3.0.3, but you should probably be importing this with import nocache = require("nocache") instead.