Search code examples
typescriptwebpacktsconfig

Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'


I'm working on a VueJS project. and we have just implemented Typescript (version 4.8.4).

I got this error error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit' after updating an interface in a ts type file.

On my tsconfig file we declare only "emitDeclarationOnly": true, but it seems that noEmit is declared with other packages under node_modules.

Here is the full content of the tsconfig file

{
  "compilerOptions": {
    "target": "es6",
    "module": "es6",
    "strict": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "noImplicitAny": false,
    "baseUrl": ".",
    "allowJs": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "declaration": true,
    "isolatedModules": true,
    "emitDeclarationOnly": true,
    "outDir": "tsdist",
    "types": [
      "webpack-env",
      "jest"
    ],
    "typeRoots": [
      "./node_modules/@types",
    ],
    "paths": {
      "@/*": [
        "src/*"
      ],
      "AppCheckout/*": ["src/assets/scripts/AppComponent/Checkout/src/*"],
      "AppCommon/*": ["src/assets/scripts/AppComponent/Common/src/*"],
      "AppPublication/*": ["src/assets/scripts/AppComponent/Publication/src/*"],
      "AppStore/*": ["src/assets/scripts/AppComponent/Store/src/*"]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
, "src/assets/scripts/globals/Container/Core/initContainer.js"  ],
  "exclude": [
    "node_modules",
    "./tasks"
  ],
  "vueCompilerOptions": {
    "target": 2.7
  }
}



Solution

  • I found the source of this problem. By the way, we use the lint-staged package on the project to validate the modifications before commits. And on the configuration file of this package, we check the typescript files by forcing the noEmit option while on the tsconfig configuration file we define emitDeclarationOnly

      "src/**/*.ts": [
        "tsc-files --noEmit"
      ],
    

    So, it was necessary to harmonize the two configurations to avoid this kind of error.