Search code examples
typescriptrollupjshelmet.js

NPM package helmet version "7.1.0" rollup error


[!] RollupError: Expected ';', '}' or <eof> (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 {
RollupError: Expected ';', '}' or <eof>
    at error (/usr/src/Node.JSRestAPI/src/webapi/node_modules/rollup/dist/shared/parseAst.js:279:30)
    at nodeConverters (/usr/src/Node.JSRestAPI/src/webapi/node_modules/rollup/dist/shared/parseAst.js:2147:9)
    at convertNode (/usr/src/Node.JSRestAPI/src/webapi/node_modules/rollup/dist/shared/parseAst.js:1032:12)
    at convertProgram (/usr/src/Node.JSRestAPI/src/webapi/node_modules/rollup/dist/shared/parseAst.js:1023:48)
    at Object.parseAstAsync (/usr/src/Node.JSRestAPI/src/webapi/node_modules/rollup/dist/shared/parseAst.js:2213:20)
    at async Module.tryParseAsync (/usr/src/Node.JSRestAPI/src/webapi/node_modules/rollup/dist/shared/rollup.js:14942:20)
    at async Module.setSource (/usr/src/Node.JSRestAPI/src/webapi/node_modules/rollup/dist/shared/rollup.js:14523:35)
    at async ModuleLoader.addModuleSource (/usr/src/Node.JSRestAPI/src/webapi/node_modules/rollup/dist/shared/rollup.js:18860:13)


npm ERR! Lifecycle script `rollup` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: [email protected] 
npm ERR!   at location: /usr/src/Node.JSRestAPI/src/webapi 
npm ERR! Lifecycle script `build` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: [email protected] 
npm ERR!   at location: /usr/src/Node.JSRestAPI/src/webapi 
ERROR: "build_webapi" exited with 1.
"typescript": "^5.3.3"
"rollup": "^4.9.4",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-typescript": "^11.1.5",

rollup.config.js:

import json from '@rollup/plugin-json';
import typescript from '@rollup/plugin-typescript';
import ts from "rollup-plugin-ts";
import tsConfig from './tsconfig.json' assert { type: "json" };
const config = [
    {
        input: "index.ts",
        output: [{ file: "build/index.js", sourcemap: true }],
        plugins: [
            typescript(
                {
                    sourceMap: tsConfig.compilerOptions.sourceMap
                }
            ),
            json()
        ]
    },
    {
        input: "index.ts",
        output: [{ file: "build/index.d.ts", "format": "es" }],
        plugins: [
            ts(
                {
                    compilerOptions: {
                        baseUrl: tsConfig.compilerOptions.baseUrl
                    }
                }
            ),
            json()
        ]
    },
]

export default config;

Solution

  • Remove redundant build/index.d.ts generation in rollup.config.js as it is configured to be generated using the Emit compilerOptions