question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error `TS5052` when `declarationDir` is set, but `declaration: false` override

See original GitHub issue

What happens and why it is wrong

Typescript compile option doesn’t allow set declaration: false and declarationDir at same time.

options error TS5052 Option 'declarationDir' cannot be specified without specifying option 'declaration'.

But according to https://github.com/Microsoft/TypeScript/issues/14184, setting with declarationDir: null and declaration: false is able to cancel emitting type files.

Unfortunately, after setting override declarationDir: null, declaration: false and useTsconfigDeclarationDir:false, in lvl 3 verbosity, terminal reports that declarationDir in parsed tsconfig is current project path. The expected declarationDir should be null.

Environment

Versions

  • typescript: 2.6.2
  • rollup: 0.55.1
  • rollup-plugin-typescript2: 0.10.0

rollup.config.js

import typescript from 'rollup-plugin-typescript2'
import camelCase from 'camel-case'

const pkg = require('./package.json')

export default {
  input: 'src/index.ts',
  output: {
    file: pkg.main,
    format: 'umd',
    name: camelCase(pkg.name),
  },
  watch: {
    include: 'src/**',
  },
  plugins: [
    typescript({
      verbosity: 3,
      tsconfigOverride: {
        compilerOptions: {
          target: 'es5',
          declaration: false,
          declarationDir: null,
        },
      },
      useTsconfigDeclarationDir: true,
    }),
  ],
}

tsconfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "target": "es6",
    "lib": ["es6", "es7", "es2017", "dom"],
    "moduleResolution": "node",
    "declarationDir": "dist/types",
    "declaration": true,
    "allowSyntheticDefaultImports": true,
  },
  "include": [
    "src/*"
  ]
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ezolenkocommented, Jan 29, 2018

Ok, I put a minimal fix in for now, try on master.

1reaction
ezolenkocommented, Jan 29, 2018

With your options, I end up passing declaration: false, declarationDir: null to typescript.parseJsonConfigFileContent(), and then typescript itself replaces declarationDir with cwd. See values in raw below.

Either this is regression in typescript, or that code path was never fixed. I’ll open a case with them.

rpt2: parsed tsconfig: {
    "options": {
        "module": 5,
        "target": 1,
        "noImplicitAny": true,
        "sourceMap": true,
        "noUnusedParameters": true,
        "noUnusedLocals": true,
        "noImplicitThis": true,
        "diagnostics": true,
        "listFiles": true,
        "pretty": true,
        "moduleResolution": 2,
        "noEmitOnError": false,
        "strictNullChecks": true,
        "forceConsistentCasingInFileNames": true,
        "noImplicitReturns": true,
        "declaration": false,
        "declarationDir": "d:/source/scr/rollup-plugin-typescript2",
        "outDir": "d:\\source\\scr\\rollup-plugin-typescript2",
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "configFilePath": "d:\\source\\scr\\rollup-plugin-typescript2/tsconfig.json"
    },
    "raw": {
        "compilerOptions": {
            "module": "es6",
            "target": "es5",
            "noImplicitAny": true,
            "sourceMap": true,
            "noUnusedParameters": true,
            "noUnusedLocals": true,
            "noImplicitThis": true,
            "diagnostics": true,
            "listFiles": true,
            "pretty": true,
            "moduleResolution": "node",
            "noEmitOnError": false,
            "strictNullChecks": true,
            "forceConsistentCasingInFileNames": true,
            "noImplicitReturns": true,
            "declaration": false,
            "declarationDir": null,
            "outDir": "./build"
        },
        "include": [
            "src/**/*.ts"
        ]
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

variable declaration doesn't compile with rollup - Stack Overflow
When I compile my code with tsc -d --emitDeclarationOnly --declarationDir build/types everything builds fine, but with rollup -c throws an ...
Read more >
@rollup/plugin-typescript - npm
When set to false, ignores any options specified in the config file. ... of outDir or declarationDir result in further TypeScript errors.
Read more >
rollup-plugin-typescript2 - npm.io
Rollup plugin for typescript with compiler errors. ... If you want to override this behavior and instead use declarationDir , set useTsconfigDeclarationDir: ...
Read more >
Rollup Plugin Typescript2: Compile TypeScript V2.0+. - Morioh
This plugin transpiles code, but doesn't change file extensions. ... Set to false if any other rollup plugins need access to declaration files....
Read more >
TypeScript errors and how to fix them
error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. Broken Code ❌. index.d ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found