-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not emit declaration files for TypeScript #1081
Comments
This doesn't seem to be a Vue issue... At least doesn't qualify as a bug report. |
But I actually emit the declaration files all along, using legacy webpack template in branch master of my project. |
I am unable to get the |
after simplifying the |
@dhensche thanks for looking into this! |
@dhensche |
yes, config.module
.rule('ts')
.use('ts-loader')
.loader('ts-loader')
.tap(opts => {
opts.transpileOnly = false;
opts.happyPackMode = false;
return opts;
}); to disable the |
Declaration files are only relevant when generating a library consumable by a package manager. I will cook up a quick PR. |
@dhensche I've tried your suggestion with vu-cli 3.0. When opts.happyPackMode = false I get the following error during build: error in ./src/index.ts
(Oddly enough, if I comment out opts.happyPackMode = false; everything is fine). |
exacly the same issue here... |
after some further investigation, it seems that (at least in my case), the issue is related with the 'thread-loader' package that the 'cli-plugin-typescript' is using... |
This is effecting me at the moment too would be great if there could be specific bit in the documentation detailing what should be done by the dev to enable outputting of declaration files when building as a lib, I appreciate if you are outputting an application you will not care about d.ts files. |
For some reason the workaround (stopping parallel, removing the happy stuff, add declaration config to tsconfig) behaviour has changed slightly in the new versions. It still outputs the d.ts files but where I used to have to use:
This will then go back to putting the d.ts files in the dist folder, for some reason it used to always work relative to the dist folder so Not a clue as to why and I dont have the time to go and investigate further but incase anyone has the same issue just change the declaration directory in your tsconfig. I would still ideally want a proper solution to this problem as some of my projects are taking 30 seconds+ to build the library with the workaround in place :( |
I'm dealing with this issue as well, and when applying the suggested workaround the type definition files are properly generated, but only on the initial build, any additional builds will clear out the dist folder and after it is rebuilt the type files are not regenerated. |
@khuguet-tfg you need to delete chainWebpack: config => {
config.module.rule("ts").uses.delete("cache-loader");
config.module.rule("tsx").uses.delete("cache-loader");
} |
Any update on this? |
Same here for library :( I have set "declaration": true, in tsconfig.json, but it doesn't output the typescript declaration files. |
Have there been any updates through almost a year? |
I just ended up removing vue-cli and using webpack directly :( it was becoming too much of a time sink and faff to build TS related libraries with vue-cli. If you are going to be doing re-usable ts based components or libraries then I would suggest just skipping vue cli and just building it all yourself with webpack, as its been almost a year now and the workarounds are not great. If you are however just making an "application" for running then vue cli is great (but I would question why you would need declaration files in that scenario). If it helps anyone, here is an example webpack used to basically do the same stuff vue cli was doing for me (bundling ts, sass, vue files etc). https://github.com/alchemist/alchemist-core/blob/master/webpack.config.js |
It does not work for me too :( |
@dhensche I want to use your solution but I got an error I created a
How to fix it and create |
Hello @HamedFathi, You need to place this code under the // vue.config.js
module.exports = {
chainWebpack: config => {
// here you can access and tweak the webpack config
}
} This is described in the docs here. have a nice day :) |
Any progress on this? |
I tried set happyPackMode to false in chainWebpack config item, and also set parallel to false, but when I try building the vue app I get stuck, after 10 minutes, I get error JavaScript heap out of memory. My Node version: 12.16.3, vue cli version 4.3.1 |
I found that my hang issue is caused by composition api library, issue link is https://github.com/vuejs/composition-api/issues/330, use command |
@Joehunk's answer works for me. I've added it in an object so I can remove it more easily when this issue is solved. /**
* 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
*/
const fixEmitDeclarationFilesForTypeScript = {
chainWebpack: (config) => {
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((options) => ({
...options,
transpileOnly: false,
happyPackMode: false,
}));
}
},
parallel: false,
};
module.exports = {
...fixEmitDeclarationFilesForTypeScript,
// some other configuration
}; However, it is indeed possible to generate the declaration files after the build of your application. All you have to do is run the {
"scripts": {
"build": "vue-cli-service build --target lib --name library src/index.ts && tsc --emitDeclarationOnly"
}
} |
That's kind of the point though haha... any progress? Anybody? |
struggled for a while with the problem, @XavierChevalier's solution works. But make sure also update the "declaration": true,
"declarationDir": "dist",
"typings": "./dist/src/index.d.ts", |
I'm using @vue/cli 4.5.6 , none of you guys solution works for me... how sad.. Oh my.. It's been 2 years past, the year of Vue3, the year of TypeScript. |
Same problem here. Does anyone know if this same problem exists in Vue 3? |
@m-thomson Yes, I finally turned to using rollup.js from scratch.. which is the approach of vue 3 repo. You might want to do so as well, I don't think this will be fixed, because this issue exists from 2018. |
For production mode I had to specify declarations via the ts-loader compiler options:
Might have something to do with the NODE_ENV getting set to EDIT: Apparently this has not resolved it. It only randomly(about 50% of the time) emits.. EDIT2: I removed the cache loader rule for vue as well, |
Ok, the transpileOnly: false and happyPackMode: false does indeed give me *.vue.d.ts files but they do not seem very useful. If I obtain a reference (ref="myComp") to a published component in an application using the library, I do not get code completion nor does it satisfy eslint; regardless of whether I am referencing props, methods or setup() results. Even using such a reference inside another component in the same library does not work. What am I missing? |
@yaquawa Since it looks like this bug is never going to get resolved, would you mind sharing your rollup configuration, please? |
@Robula Here you go https://github.com/yaquawa/muku-ui/blob/master/rollup.config.js |
@nelisbijl I was able to at least get the benefit of eslint rules being quiet in downstream projects by renaming the types file from *.vue.d.ts to *.d.ts I'm still unfortunately not getting intellisense working though. Any chance you got this working? Also working with Vue2 SFCs. |
@william-will-angi No I ended up adding and exporting additional interfaces alongside the components. Component is exported as Vue and interface as . Very unsatisfying. ** EDITED **
This seems to work quite well. Still wondering why this is so poorly documented (if at all). |
Same issue. Very unsatisfying to have this still open. |
This should be automatically built into Why would I ever want to export a library build of vue component without types? It guarantees compiler warnings on the client side who uses the library. |
With the fix suggested here I get ts errors on intermediate files
Any idea how to solve this? |
Still can't figure out how to export the type declaration: vuejs/vue-cli#1081
With VueJS 3 you can use https://github.com/johnsoncodehk/volar/tree/master/packages/vue-tsc This will generate the declaration file where you have set your |
In 2024, this problem is still alive. Too terrible. |
I thought vue-cli was deprecated anyway, so it should come as no suprise that no more development is going on. |
Yeah you're better off swapping to vite @seamory @bodograumann, vue cli is dead. |
Version
3.0.0-beta.6
Reproduction link
https://github.com/HuijiFE/void-ui/tree/0.1
Steps to reproduce
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.The text was updated successfully, but these errors were encountered: