helmetjs / helmet

Help secure Express apps with various HTTP headers

Home Page:https://helmetjs.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Unexpected token` when importing `*.d.cts` or `*.d.mts` files from helmet

phun-ky opened this issue · comments

I'm trying to bundle helmet with rollup-plugin-typescript2, but I keep getting this error, is it related directly to helmet or is this a ts/rpt2 issue?

[!] (plugin rpt2) RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)
../../node_modules/helmet/index.d.cts (3:5)
1: import {IncomingMessage, ServerResponse} from "http"
2: 
3: type ContentSecurityPolicyDirectiveValueFunction = (req: IncomingMessage, res: ServerResponse) => string
        ^
4: type ContentSecurityPolicyDirectiveValue = string | ContentSecurityPolicyDirectiveValueFunction
5: interface ContentSecurityPolicyOptions {

    at error (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:279:30)
    at Module.error (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:13947:16)
    at Module.tryParse (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:14658:25)
    at Module.setSource (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:14260:39)
    at ModuleLoader.addModuleSource (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:24225:20)
[!] (plugin rpt2) RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)
../../node_modules/helmet/index.d.mts (3:5)
1: import {IncomingMessage, ServerResponse} from "http"
2: 
3: type ContentSecurityPolicyDirectiveValueFunction = (req: IncomingMessage, res: ServerResponse) => string
        ^
4: type ContentSecurityPolicyDirectiveValue = string | ContentSecurityPolicyDirectiveValueFunction
5: interface ContentSecurityPolicyOptions {

    at error (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:279:30)
    at Module.error (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:13947:16)
    at Module.tryParse (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:14668:25)
    at Module.setSource (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:14270:39)
    at ModuleLoader.addModuleSource (/home/alexander/Workspace/company/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:24266:20)

The original issue is here: ezolenko/rollup-plugin-typescript2#446

I'm not sure, but I assume this is an issue with the Rollup plugin. Helmet's type definitions look correct to me, and seem to be working well for others.

I'm going to close this issue, but let me know if that's wrong and I can reopen.