ezolenko / rollup-plugin-typescript2

Rollup plugin for typescript with compiler errors.
MIT License
819 stars 71 forks source link

rpt2 not ignoring `*.d.cts` and `*.d.mts` files (resulting in `Unexpected token` error) #446

Closed phun-ky closed 1 year ago

phun-ky commented 1 year ago

Troubleshooting

  1. Does tsc have the same output? If so, please explain why this is incorrect behavior

    N/A

  2. Does your Rollup plugin order match this plugin's compatibility? If not, please elaborate

    yes

  3. Can you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction

    https://stackblitz.com/edit/rpt2-repro-3j5vny?file=src%2Findex.ts,package.json,src%2Flib%2Findex.ts,README.md,tsconfig.json

What happens and why it is incorrect

Error is thrown, should have support for *.cts/*.mts files

[!] (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)

Environment

Ubuntu 22.04

Versions

  System:
    OS: Linux 5.17 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
    Memory: 43.96 GB / 62.51 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 18.16.0 - /usr/local/bin/node
    npm: 9.5.1 - /usr/local/bin/npm
  npmPackages:
    rollup: ^3.22.0 => 3.22.0 
    rollup-plugin-typescript2: ^0.34.1 => 0.34.1 
    typescript: ^5.0.4 => 5.0.4 
  npmGlobalPackages:
    typescript: 5.0.4

rollup.config.js

:
```js /* global process */ import { nodeResolve } from '@rollup/plugin-node-resolve'; import ts from 'rollup-plugin-typescript2'; import dts from 'rollup-plugin-dts'; import json from '@rollup/plugin-json'; import typescript from 'typescript'; import terser from '@rollup/plugin-terser'; import commonjs from '@rollup/plugin-commonjs'; import externals from 'rollup-plugin-node-externals'; const PACKAGE_NAME = process.cwd(); export default [ { input: `${PACKAGE_NAME}/src/index.ts`, output: { dir: `${PACKAGE_NAME}/dist`, format: 'es' }, plugins: [ externals(), json(), nodeResolve({ preferBuiltins: false }), commonjs(), ts({ useTsconfigDeclarationDir: false, sourceMap: false, typescript, tsconfig: `${PACKAGE_NAME}/tsconfig.json` }), terser() ] }, { input: `${PACKAGE_NAME}/dist/index.d.ts`, output: [{ file: `${PACKAGE_NAME}/dist/index.d.ts`, format: 'es' }], plugins: [dts()] } ]; ```

tsconfig.json

:
```json5 { "compilerOptions": { "module": "ES2020", "target": "es2022", "lib": ["ES2021", "dom", "dom.iterable"], "sourceMap": true, "declaration": true, // "declarationDir": "./dts", "moduleResolution": "node", "rootDirs": ["middlewares", "utils", "routes"], "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": false, "strictNullChecks": true, "esModuleInterop": true, "typeRoots": ["./@types", "./node_modules/@types"], "resolveJsonModule": true, "types": ["node"] }, "exclude": ["__tests__", "node_modules", "dist", "*.d.ts", "*.d.cts"] } ```

package.json

:
```json { "name": "@kilabs/devplatform-server-api", "type": "module", "private": true, "version": "0.0.1", "description": "The API monorepo for the devplatform", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "commit": "npx git-cz" }, "author": "Alexander Vassbotn Røyne-Helgesen ", "license": "SEE LICENSE IN LICENSE", "devDependencies": { "@rollup/plugin-commonjs": "^24.1.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.2", "@rollup/plugin-terser": "^0.4.1", "@types/express": "^4.17.17", "@typescript-eslint/eslint-plugin": "^5.54.1", "@typescript-eslint/parser": "^5.54.1", "eslint": "^8.25.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.5.0", "eslint-plugin-compat": "^4.1.2", "eslint-plugin-import": "^2.27.5", "eslint-plugin-prettier": "^4.2.1", "lerna": "^6.6.2", "prettier": "^2.7.1", "prettier-eslint": "^15.0.1", "rollup": "^3.22.0", "rollup-plugin-dts": "^5.3.0", "rollup-plugin-node-externals": "^6.0.1", "rollup-plugin-typescript2": "^0.34.1", "tslib": "^2.3.1", "typescript": "^5.0.4" }, "workspaces": [ "utils/*", "routes/*", "middlewares/*" ] } ```
phun-ky commented 1 year ago

Perhaps this is relevant: https://github.com/rollup/plugins/issues/1480

agilgur5 commented 1 year ago

So declaration files are not supposed to be directly imported in TS. TS picks them up without imports. See #273 for some more details.

phun-ky commented 1 year ago

@agilgur5 well, that kind of goes without saying :) but I am not including the declaration files directly, nor is helmet.

ezolenko commented 1 year ago

@phun-ky try explicitly including d.cts and d.mts:

include: [ "*.ts+(|x)", "**/*.ts+(|x)", '**/*.d.cts', '**/*.d.mts' ]

This will run them through typescript and I guess produce empty js.

Somehow import 'helmet' resolves to .d.cts:

rpt2: dependency '/home/projects/rpt2-repro-vnppxj/node_modules/helmet/index.d.cts'
rpt2:     imported by '/home/projects/rpt2-repro-vnppxj/src/index.ts'
rpt2: resolving 'helmet' imported by '/home/projects/rpt2-repro-vnppxj/src/index.ts'
rpt2:     to '/home/projects/rpt2-repro-vnppxj/node_modules/helmet/index.d.cts'
ezolenko commented 1 year ago

Ah, ignore that -- this fixes the problem:

include: [ "*.ts+(|x)", "**/*.ts+(|x)", '**/*.cts', '**/*.mts' ]
ezolenko commented 1 year ago

@phun-ky could you try building your whole repo with master branch of the plugin?

phun-ky commented 1 year ago

@ezolenko still got issues, sorry for the late reply!

/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/src/index.ts → dist...
[!] (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 (/usr/local/lib/node_modules/rollup/dist/shared/rollup.js:279:30)
    at Module.error (/usr/local/lib/node_modules/rollup/dist/shared/rollup.js:13933:16)
    at Module.tryParse (/usr/local/lib/node_modules/rollup/dist/shared/rollup.js:14644:25)
    at Module.setSource (/usr/local/lib/node_modules/rollup/dist/shared/rollup.js:14246:39)
    at ModuleLoader.addModuleSource (/usr/local/lib/node_modules/rollup/dist/shared/rollup.js:24211:20)
ezolenko commented 1 year ago

@phun-ky could you post verbose output when building with master branch and your rollup config if different from what you already posted?

phun-ky commented 1 year ago

Here is the verbose output, tsconfig.json should be unchanged imho:

npm run build

:
```bash > @kilabs/csp@0.0.1 prebuild > npm run clean > @kilabs/csp@0.0.1 clean > rm -rf dist/* > @kilabs/csp@0.0.1 build > rollup -c ../../../rollup.config.js  /home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/src/index.ts → dist... rpt2: built-in options overrides: { "noEmitHelpers": false, "importHelpers": true, "noResolve": false, "noEmit": false, "noEmitOnError": false, "inlineSourceMap": false, "outDir": "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/node_modules/.cache/rollup-plugin-typescript2/placeholder", "moduleResolution": 2, "allowNonTsExtensions": true } rpt2: parsed tsconfig: { "options": { "module": 6, "target": 9, "lib": [ "lib.es2021.d.ts", "lib.dom.d.ts", "lib.dom.iterable.d.ts" ], "sourceMap": true, "declaration": true, "moduleResolution": 2, "rootDirs": [ "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes" ], "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": false, "strictNullChecks": true, "esModuleInterop": true, "typeRoots": [ "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/types/dist", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types" ], "resolveJsonModule": true, "configFilePath": "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/tsconfig.json", "noEmitHelpers": false, "importHelpers": true, "noResolve": false, "noEmit": false, "noEmitOnError": false, "inlineSourceMap": false, "outDir": "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/node_modules/.cache/rollup-plugin-typescript2/placeholder", "allowNonTsExtensions": true }, "fileNames": [ "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/src/index.ts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/src/lib/index.ts" ], "typeAcquisition": { "enable": false, "include": [], "exclude": [] }, "raw": { "extends": "../../../tsconfig.json", "include": [ "src" ], "exclude": [ "__tests__", "node_modules", "dist" ], "compileOnSave": false }, "errors": [], "wildcardDirectories": { "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/src": 1 }, "compileOnSave": false } rpt2: typescript version: 5.0.4 rpt2: tslib version: 2.5.2 rpt2: rollup version: 3.23.0 rpt2: rollup-plugin-typescript2 version: 0.35.0 rpt2: plugin options: { "check": true, "verbosity": 3, "clean": false, "cacheRoot": "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/node_modules/.cache/rollup-plugin-typescript2", "include": [ "*.ts+(|x)", "**/*.ts+(|x)", "**/*.cts", "**/*.mts" ], "exclude": [ "*.d.ts", "**/*.d.ts", "**/*.d.cts", "**/*.d.mts" ], "abortOnError": true, "rollupCommonJSResolveHack": false, "tsconfig": "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/tsconfig.json", "useTsconfigDeclarationDir": false, "tsconfigOverride": {}, "transformers": [], "tsconfigDefaults": {}, "objectHashIgnoreUnknownHack": false, "cwd": "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp", "sourceMap": false, "typescript": "version 5.0.4" } rpt2: rollup config: { "external": [], "input": "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/src/index.ts", "plugins": [ { "name": "commonjs--resolver" }, { "name": "node-externals" }, { "name": "json" }, { "name": "node-resolve", "version": "15.1.0", "resolveId": { "order": "post" } }, { "name": "commonjs", "version": "24.1.0" }, { "name": "rpt2" }, { "name": "terser", "numOfWorkersUsed": 0 }, { "name": "stdin" } ], "output": [ { "dir": "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/dist", "format": "es", "plugins": [] } ] } rpt2: tsconfig path: /home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/tsconfig.json rpt2: included: [ "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/*.ts+(|x)", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/**/*.ts+(|x)", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/**/*.cts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/**/*.mts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/*.ts+(|x)", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/**/*.ts+(|x)", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/**/*.cts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/**/*.mts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes/*.ts+(|x)", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes/**/*.ts+(|x)", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes/**/*.cts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes/**/*.mts" ] rpt2: excluded: [ "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/*.d.ts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/**/*.d.ts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/**/*.d.cts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/**/*.d.mts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/*.d.ts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/**/*.d.ts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/**/*.d.cts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/utils/**/*.d.mts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes/*.d.ts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes/**/*.d.ts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes/**/*.d.cts", "/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/routes/**/*.d.mts" ] rpt2: Ambient types: rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/body-parser/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/connect/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/eslint/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/estree/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/express/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/express-serve-static-core/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/json-schema/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/json5/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/mime/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/minimatch/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/minimist/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/node/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/normalize-package-data/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/parse-json/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/prettier/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/qs/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/range-parser/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/resolve/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/semver/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/send/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/serve-static/index.d.ts rpt2: /home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/@types/triple-beam/index.d.ts rpt2: transpiling '/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/src/index.ts' rpt2: cache: '/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/node_modules/.cache/rollup-plugin-typescript2/rpt2_ad1e91f63e44e82502b19742dbcf61dc242816c9/code/cache/c258cafb91815df26891c418aeefaeaea28a6d64' rpt2:  cache hit rpt2: cache: '/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/node_modules/.cache/rollup-plugin-typescript2/rpt2_ad1e91f63e44e82502b19742dbcf61dc242816c9/syntacticDiagnostics/cache/c258cafb91815df26891c418aeefaeaea28a6d64' rpt2:  cache hit rpt2: cache: '/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/node_modules/.cache/rollup-plugin-typescript2/rpt2_ad1e91f63e44e82502b19742dbcf61dc242816c9/semanticDiagnostics/cache/c258cafb91815df26891c418aeefaeaea28a6d64' rpt2:  cache hit rpt2: generated declarations for '/home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp/src/index.ts' rpt2: rolling caches [!] (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/knowit/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:278:30) at Module.error (/home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:13958:16) at Module.tryParse (/home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:14679:25) at Module.setSource (/home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:14281:39) at ModuleLoader.addModuleSource (/home/alexander/Workspace/knowit/internal/devplatform-server-api/node_modules/rollup/dist/shared/rollup.js:24277:20) npm ERR! Lifecycle script `build` failed with error: npm ERR! Error: command failed npm ERR! in workspace: @kilabs/csp@0.0.1 npm ERR! at location: /home/alexander/Workspace/knowit/internal/devplatform-server-api/packages/middlewares/csp ```
ezolenko commented 1 year ago

So this run succeeded? Try doing a clean build

phun-ky commented 1 year ago

Crap, no, parts of the log is missing

phun-ky commented 1 year ago

@ezolenko updated the comment with the output now, sorry

phun-ky commented 1 year ago

What's weird is that this works like a charm:

$ ts-node --esm --project tsconfig.json src/index.ts
phun-ky commented 1 year ago

Any progress on this issue? :)

ezolenko commented 1 year ago

@phun-ky the progress is slow :)

Could you try mts branch (set this in your package.json: "rollup-plugin-typescript2": "git@github.com:ezolenko/rollup-plugin-typescript2.git#mts",)

Your example project compiles for me on that branch.

phun-ky commented 1 year ago

@ezolenko yep! that worked like a charm!

ezolenko commented 1 year ago

Ok, I'll make a release with the last few fixes

ezolenko commented 1 year ago

In 0.35.0 now

phun-ky commented 1 year ago

@ezolenko thanks for the great work! I really appreciate it!

agilgur5 commented 1 year ago

@agilgur5 well, that kind of goes without saying :) but I am not including the declaration files directly, nor is helmet.

Ah, sorry for not checking this in more depth earlier! Was on my phone and just responded real quick to the title. We've had a lot of folks trying to import .d.ts files in the past so thought that a quick response with a link to a similar issue might be helpful.

Glad that ezolenko had some time to spare and could help in more depth that same day!

root cause analysis

Somehow import 'helmet' resolves to .d.cts:

So I did root cause this as I was curious how the heck that happened as that's definitely not correct behavior. Took me a bit to find Helmet's package.json as it is dynamically generated. Its current version's internal only have .cjs, .mjs, .cts extensions, which rpt2 did not previously support. Specifically, rpt2 resolved one of the references to the index.d.cts file, which is a possible correct resolution, but rpt2 is supposed to ignore declarations. Those checks detected declarations as files with .d.ts, so ezolenko had to change this line and our default exclude filter to now also ignore .d.cts and .d.mts as those are now possible extensions in newer TS versions.

That is to say, the Unexpected token error is actually correct, as rpt2 shouldn't be reading declarations, but it shouldn't be loading declarations into Rollup at all to begin with. It just didn't know the new file extensions in order to ignore them. Will rename the issue to make that clearer.

irony of incomplete branches

In a bout of extreme irony, when I looked at my local code, I actually already had a similar line there 😵‍💫🤔 It turns out while I was attempting to fix #426 back in October (never quite finished that, partly because I was having trouble with Rollup ESM config), I made this commit on one of my branches containing the exact same line 😅