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.

ref is not defined for production build

See original GitHub issue

works fine in development mode, but in production build with npm run build, it shows ‘ref is not defined’

<template>
  <div ref="divRef">test</div>
</template>

<script setup>
const divRef = ref(null);
</script>

<style scoped></style>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kaiser-9527commented, Jan 6, 2022

my-project.zip please refer to attached files. Thanks. It seems that the plugin auto imports unref for the Template Refs, if I just use simple ref object, it can work both in development mode and production build

<template>
   <div>
    {{message}}
  </div>
</template>
<script setup>
const message = ref('hello')
</script>

however, if I ref to template element or component instance, it can work in development mode but it doesn’t work for production build

<template>
  <div ref="divRef">test</div>
</template>

<script setup>
const divRef = ref(null);
</script>
<template>
  <main>{{ count }}</main>
</template>
<script setup lang="ts">
const count = ref([1, 3])
</script>

It’s a simple ref usage, but also got the same error error TS2304: Cannot find name 'ref'., the version is "unplugin-auto-import": "^0.5.5". like this plugin vary much, but got this error, is depressed

1reaction
antfucommented, Jan 22, 2022

Please upgrade to the latest version and try again. If it still fails to you, please send a PR to add a failed tests under https://github.com/antfu/unplugin-auto-import/tree/main/test/fixtures. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactJs: refs is not defined (no-undef) - Stack Overflow
In the following code, I wrapped your code a function component and use React.createRef() to create a ref and assign to okanhzai.
Read more >
ReferenceError is not defined errors in production but works in ...
I made my first vue3 app, it is working in development but not in production (vite build). I've managed to replicate it like...
Read more >
ReferenceError: “process is not defined” - GIMTEC
In NodeJS, “process” is defined, but not in the browser. This is because NodeJS and the browser are different runtime environments.
Read more >
How to Fix ReferenceError: Event is Not Defined in JavaScript
The Javascript ReferenceError is thrown when an attempt is made to reference a non-existing or out of scope variable. Not defining a ...
Read more >
Angular - ReferenceError x is not defined - Web - v5 - IMG.LY
The ReferenceError: x is not defined error message will appear if you use the optimization option in the angular.json . The additional uglification...
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