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.

Can not emit declaration files for TypeScript

See original GitHub issue

Version

3.0.0-beta.6

Reproduction link

https://github.com/HuijiFE/void-ui/tree/0.1

Steps to reproduce

git clone git@github.com:HuijiFE/void-ui.git
cd void-ui
git checkout 0.1
yarn
yarn build:void

What is expected?

Output declaration files after building.

What is actually happening?

There is not any declaration files after building.


I have set "declaration": true, in tsconfig.json, but it doesn’t output the typescript declaration files.

And then I use tsc --emitDeclarationOnly, although it output the declaration files but without vue single file component.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:27
  • Comments:51 (7 by maintainers)

github_iconTop GitHub Comments

26reactions
Joehunkcommented, Dec 5, 2019

I just hit this issue myself. The solution for me was substantially similar to some of the previous ones claimed to work, but with some key differences. This is my vue.config.js:

module.exports = {
  chainWebpack: config => {
    // These are some necessary steps changing the default webpack config of the Vue CLI
    // that need to be changed in order for Typescript based components to generate their
    // declaration (.d.ts) files.
    //
    // Discussed here https://github.com/vuejs/vue-cli/issues/1081
    if(process.env.NODE_ENV === 'production') {
      config.module.rule("ts").uses.delete("cache-loader");

      config.module
        .rule('ts')
        .use('ts-loader')
        .loader('ts-loader')
        .tap(opts => {
          opts.transpileOnly = false;
          opts.happyPackMode = false;
          return opts;
        });
    }
  },
  parallel: false,
}

In particular, the section in previous examples that disabled thread-loader had no effect. I had to add parallel: false to avoid the error Cannot read property 'options' of undefined.

Additionally (this is obvious but bears mentioning), you must specify "declaration": true in your tsconfig.json to have declaration files emitted. This is with the latest (4.1.x) Vue CLI.

22reactions
wizardnet972commented, Dec 22, 2018

Same here for library 😦 npx vue-cli-service build --target lib --dest lib ./src/index.ts

I have set “declaration”: true, in tsconfig.json, but it doesn’t output the typescript declaration files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Creating .d.ts Files from .js files - TypeScript
emitDeclarationOnly ": true,. // Types should go into this directory. // Removing this would place the .d.ts files. // next to the .js...
Read more >
typescript - How to emit TS declarations for legacy CommonJS ...
I checked TypeScript's own code, and there's no evident way to change how the declare module line is generated. Fortunately, you can just ......
Read more >
@rollup/plugin-typescript - npm
Having @rollup/plugin-typescript only do typechecking / declarations with "emitDeclarationOnly": true while deferring to @rollup/plugin-babel ...
Read more >
Compiler Options - TypeScript
Option Type Default ‑‑allowJs boolean false ‑‑allowSyntheticDefaultImports boolean module === "system" or ‑‑esModuleInterop ‑‑allowUmdGlobalAccess boolean false
Read more >
Webpack and TypeScript can't resolve declaration file for Vue ...
Coding example for the question Webpack and TypeScript can't resolve declaration file for Vue-Vue.js.
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