Skip to content

emitDeclarationOnly in v0.33.0 -- what if I want an empty chunk and only declarations? #411

Closed
@BitPatty

Description

@BitPatty

Troubleshooting

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

No

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

Yes

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

https://stackblitz.com/edit/rpt2-repro-1kadjh?file=package.json

What happens and why it is incorrect

The build crashes if emitDeclarationOnly is set to true in overrides or tsconfig. tsc produces the correct output. Used to work until v0.33.0.

Environment

Versions

  System:
    OS: Linux 5.4 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (4) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
    Memory: 5.13 GB / 7.77 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 18.4.0 - /usr/local/share/nvm/versions/node/v18.4.0/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.18.0 - /usr/local/share/nvm/versions/node/v18.4.0/bin/npm
  npmPackages:
    rollup: 2.78.0 => 2.78.0 
    rollup-plugin-typescript2: 0.33.0 => 0.33.0 
    typescript: 4.7.4 => 4.7.4 

rollup.config.js

:
import typescript from 'rollup-plugin-typescript2';

export default {
  input: './src/index.ts',
  output: {
    file: './dist/index.ts',
    format: 'esm',
    exports: 'named',
  },
  plugins: [
    typescript({
      verbosity: 3,
      clean: true,
    }),
  ],
};

tsconfig.json

:
{
  // https://github.com/agilgur5/tsconfig
  "extends": "@agilgur5/tsconfig/src/tsconfig.library.json",
  // exclude node_modules (the default), dist dir, coverage dir, and example for now
  "exclude": ["node_modules/", "dist/", "coverage/", "example/"],
  // all TS files in the src/ dir
  "include": ["src/**/*"],
  // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
  "compilerOptions": {
    // output to dist/ dir
    "outDir": "./dist/",
    // match output dir to input dir. e.g. dist/index instead of dist/src/index
    "rootDir": "./src",
    "emitDeclarationOnly": true
  }
}

package.json

:
{
  "name": "rpt2-repro",
  "version": "0.0.0",
  "scripts": {
    "clean": "rm -rf dist/",
    "build": "rollup -c",
    "tsc": "tsc"
  },
  "devDependencies": {
    "@agilgur5/tsconfig": "^0.0.2",
    "rollup": "^2.75.6",
    "rollup-plugin-typescript2": "^0.33.0",
    "typescript": "^4.7.3"
  }
}

plugin output with verbosity 3

:
./src/index.ts → ./dist/index.ts...
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "noEmitOnError": false,
    "inlineSourceMap": false,
    "outDir": "/home/projects/rpt2-repro-1kadjh/node_modules/.cache/rollup-plugin-typescript2/placeholder",
    "moduleResolution": 2,
    "allowNonTsExtensions": true,
    "module": 5
}
rpt2: parsed tsconfig: {
    "options": {
        "strict": true,
        "allowUnusedLabels": false,
        "allowUnreachableCode": false,
        "exactOptionalPropertyTypes": true,
        "noFallthroughCasesInSwitch": true,
        "noImplicitOverride": true,
        "noImplicitReturns": true,
        "noPropertyAccessFromIndexSignature": true,
        "noUncheckedIndexedAccess": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "importsNotUsedAsValues": 2,
        "checkJs": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "outDir": "/home/projects/rpt2-repro-1kadjh/node_modules/.cache/rollup-plugin-typescript2/placeholder",
        "sourceMap": true,
        "moduleResolution": 2,
        "resolveJsonModule": true,
        "jsx": 2,
        "noEmit": false,
        "declaration": true,
        "declarationMap": true,
        "rootDir": "/home/projects/rpt2-repro-1kadjh/src",
        "emitDeclarationOnly": true,
        "configFilePath": "/home/projects/rpt2-repro-1kadjh/tsconfig.json",
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmitOnError": false,
        "inlineSourceMap": false,
        "allowNonTsExtensions": true,
        "module": 5
    },
    "fileNames": [
        "/home/projects/rpt2-repro-1kadjh/src/index.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "extends": "@agilgur5/tsconfig/src/tsconfig.library.json",
        "exclude": [
            "node_modules/",
            "dist/",
            "coverage/",
            "example/"
        ],
        "include": [
            "src/**/*"
        ],
        "compilerOptions": {
            "outDir": "./dist/",
            "rootDir": "./src",
            "emitDeclarationOnly": true
        },
        "compileOnSave": false
    },
    "errors": [],
    "wildcardDirectories": {
        "/home/projects/rpt2-repro-1kadjh/src": 1
    },
    "compileOnSave": false
}
rpt2: typescript version: 4.7.3
rpt2: tslib version: 2.4.0
rpt2: rollup version: 2.75.6
rpt2: rollup-plugin-typescript2 version: 0.33.0
rpt2: plugin options:
{
    "check": true,
    "verbosity": 3,
    "clean": true,
    "cacheRoot": "/home/projects/rpt2-repro-1kadjh/node_modules/.cache/rollup-plugin-typescript2",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false,
    "cwd": "/home/projects/rpt2-repro-1kadjh",
    "typescript": "version 4.7.3"
}
rpt2: rollup config:
{
    "external": [],
    "input": "./src/index.ts",
    "plugins": [
        {
            "name": "rpt2"
        },
        {
            "name": "stdin"
        }
    ],
    "output": [
        {
            "exports": "named",
            "file": "./dist/index.ts",
            "format": "esm",
            "plugins": []
        }
    ]
}
rpt2: tsconfig path: /home/projects/rpt2-repro-1kadjh/tsconfig.json
rpt2: included:
[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]
rpt2: excluded:
[
    "*.d.ts",
    "**/*.d.ts"
]
rpt2: transpiling '/home/projects/rpt2-repro-1kadjh/src/index.ts'
rpt2: generated declarations for '/home/projects/rpt2-repro-1kadjh/src/index.ts'
rpt2: emitDeclarationOnly enabled, not transforming TS'
[!] (plugin rpt2) Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/index.ts (4:29)
2: // run `npm run tsc` in the terminal to type-check this file with tsc
3: 
4: export default function sum(a: number, b: number) {
                                ^
5:   return a + b;
6: }

    at error (/home/projects/rpt2-repro-1kadjh/node_modules/rollup/dist/shared/rollup.js:198:30)
    at Module.error (/home/projects/rpt2-repro-1kadjh/node_modules/rollup/dist/shared/rollup.js:12553:16)
    at Module.tryParse (/home/projects/rpt2-repro-1kadjh/node_modules/rollup/dist/shared/rollup.js:12930:25)
    at Module.setSource (/home/projects/rpt2-repro-1kadjh/node_modules/rollup/dist/shared/rollup.js:12835:24)
    at ModuleLoader.addModuleSource (/home/projects/rpt2-repro-1kadjh/node_modules/rollup/dist/shared/rollup.js:22309:20)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: questionThis is a usage or similar questionkind: supportAsking for support with something or a specific use casescope: integrationRelated to an integration, not necessarily to core (but could influence core)solution: intended behaviorThis is not a bug and is expected behaviorsolution: workaround availableThere is a workaround available for this issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions