Skip to content
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

Cannot find name defineProps ts error #102

Open
jacekkarczmarczyk opened this issue Jan 20, 2022 · 7 comments
Open

Cannot find name defineProps ts error #102

jacekkarczmarczyk opened this issue Jan 20, 2022 · 7 comments
Labels
documentation Improvements or additions to documentation pr welcome

Comments

@jacekkarczmarczyk
Copy link

jacekkarczmarczyk commented Jan 20, 2022

In a vue2 + vite + unplugin-vue2-script-setup project i have a ts error (not eslint) on build that Cannot find name defineProps/defineEmits

Here's project's tsconfig https://github.com/jacekkarczmarczyk/rachunek/blob/master/tsconfig.json and example usage of defineProps https://github.com/jacekkarczmarczyk/rachunek/blob/master/src/components/BillForm/BillForm.vue#L163 (that's not a minimal repro, but I guess just the settings files are imporant, if you want a minimal repro though let me know)

To reproduce the issue run yarn build

screenshot

Error can be supressed with // @ts-ignore but that doesn't sound like a valid solution. Another option is to add .d.ts files with defineProps declaration but I think that should be rather provided by the lib (or maybe it is but can't find anything)

@xiaoxiangmoe
Copy link
Collaborator

  • remove src/shims-tsx.d.ts.
  • remove src/shims-vue.d.ts
  • create empty file src/shims-vue.d.ts and add /// <reference types="unplugin-vue2-script-setup/shims.js" />

Example Project: https://github.com/antfu/unplugin-vue2-script-setup/blob/main/examples/vue-cli/src/shims-vue.d.ts

@jacekkarczmarczyk
Copy link
Author

Thanks, but that doesn't seem to work, not only it didn't solve the problem with unrecognized defineProps but also added problem with recognizing .vue files:

image

and with JSX syntax:

image

Adding /// <reference types="unplugin-vue2-script-setup/shims.js" /> to existing vue shim didn't help as well.

Also this example project is a vue-cli project and mine is vite, maybe that matters.

@xiaoxiangmoe xiaoxiangmoe self-assigned this Jan 20, 2022
@xiaoxiangmoe
Copy link
Collaborator

xiaoxiangmoe commented Jan 20, 2022

  • yarn add --dev @vue/runtime-dom
  • do one of below
    • add "allowJs": true, in your tsconfig to allow js <script>
    • or change js <script> to ts <script lang="ts">

@jacekkarczmarczyk
Copy link
Author

jacekkarczmarczyk commented Jan 20, 2022

yarn add --dev @vue/runtime-dom

Thank you, that was it! I have lang="ts" in all components so no need for other steps, also seems that /// <reference types="unplugin-vue2-script-setup/shims.js" /> is not necessary as well

I've pushed changes to the repo, now it compiles fine, however I'll leave this issue open as I consider it to be the documentation issue. Readme says:

We recommend using VS Code with Volar to get the best experience (You might want to disable Vetur if you have it).
When using Volar, you need to install @vue/runtime-dom as devDependencies to make it work on Vue 2.

I'm not using Volar or VS Code so I've skipped this step, but it seems that you need to add the dependency anyway.

@xiaoxiangmoe
Copy link
Collaborator

@jacekkarczmarczyk vue-tsc is volar @_@

@jacekkarczmarczyk
Copy link
Author

jacekkarczmarczyk commented Jan 20, 2022

hm what is https://github.com/johnsoncodehk/volar then? nvm, I see now
still i think that putting information about dependency in the IDE section is misleading, writing about Vetur, Volar and VS Code in one sentence may make people think that it's about using Volar extension in VS Code

@xiaoxiangmoe xiaoxiangmoe removed their assignment Feb 22, 2022
@xiaoxiangmoe xiaoxiangmoe added the documentation Improvements or additions to documentation label Mar 4, 2022
@andygeek
Copy link

andygeek commented Jun 12, 2022

It happens to me because I didn't give it npm install, but then you have to disabled Vetur if you have it installed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation pr welcome
Projects
None yet
Development

No branches or pull requests

3 participants