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.

'Cannot find name' errors for no reason

See original GitHub issue

Volar works perfectly for all files, except for one. For some reason it thinks that I’m using “JSX” in templates. Here is code:

<template> 
  <div id="roundchat" class="roundchat chat">
    <div class="chatroom">
      Chat room
      <input
        id="checkbox"
        title="Toggle the chat"
        name="checkbox"
        type="checkbox"
        @click="toggle"
      />
    </div>
    <ol id="lobbychat-messages">
      <div id="messages" v-if="hiddenChat">
        <li v-for="i in messages" :key="i" class="message">
          <div class="time">{{ i.time }}</div>
          <span class="user">
            <a href="/">{{ i.user }}</a>
          </span>
          <span> {{ i.message }} </span>
        </li>
      </div>
    </ol>

    <input
      v-model="message"
      v-on:keyup.enter="onEnter"
      id="chat-entry"
      maxlength="140"
      type="text"
      name="entry"
      autocomplete="off"
      :placeholder="setPlaceholder()"
    />
  </div>
</template>

<script setup lang="ts">
import { ref, Ref } from "vue";


const props = defineProps({ messages: [], wsType: String });
const messages: Ref<ChatMessage[]> = ref(props.messages!);
const message = ref("");
const hiddenChat = ref(true);


function onEnter(): void {
  if (message.value.length > 0 && message.value.length < 80) {
    //ws.send...
    message.value = "";
  }
}

function setPlaceholder(): string {
  let reg = false;
  if (reg == false) {
    return "Sign in to chat";
  } else {
    return "Please be nice in the chat!";
  }
}

function toggle(): void {
  hiddenChat.value = !hiddenChat.value;
}

interface ChatMessage {
  time: String;
  user: String;
  message: String;
}
</script>

<style scoped>
.user {
  padding-right: 6px;
  font-weight: bold;
}
</style>

Project made with: Vue + Vite + Ts And when I want to use this component in my view, TypeScript complains with:

JSX element class does not support attributes because it does not have a '$props' property

Component inside view.

<template>
  <ChatRoom :messages="[]" wsType="home_chat_message" />
</template>

<script setup lang="ts">
import ChatRoom from '@/components/ChatRoom.vue';
</script>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
xiaoxiangmoecommented, Mar 17, 2022

You should use const props = defineProps({ messages: Array as PropType<Array<ChatMessage>>, wsType: String });


But I prefer use

const props = defineProps<{
  messages: Array<ChatMessage>;
  wsType: string;
}>();
0reactions
uros-5commented, Mar 17, 2022

You should use const props = defineProps({ messages: Array as PropType<Array<ChatMessage>>, wsType: String });

But I prefer use

const props = defineProps<{
  messages: Array<ChatMessage>;
  wsType: string;
}>();

This fixed the issue, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular and Typescript: Can't find names - Error: cannot find ...
This fixed a lot of errors for me, but I still get errors like TS2304: Cannot find name 'module' and TS2339: Property 'find'...
Read more >
Fix the Cannot Find Name 'require' Error in TypeScript
To fix the “cannot find name 'require'” error in TypeScript, install the @types/node package into your project by running npm i -D ...
Read more >
TypeScript error TS2304 cannot find name require - Edureka
The error that I'm getting is the "TS2304: Cannot find name 'require' " when I attempt to transpile a simple TypeScript Node.js page....
Read more >
TS2304: Cannot find name 'Request' · Issue #661 - GitHub
When compiling a Typescript file that uses MeiliSearch for Node.js, the error TS2304: Cannot find name 'Request' causes the build to fail.
Read more >
Typescript getting error TS2304 cannot find name ' require'
If you are using TypeScript 2.x you no longer need to have Typings or Definitely Typed installed. Simply install the following package.
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