"document is not defined" when using bootstrap js
See original GitHub issueSo I have this component which uses collapse.js
of bootstrap
,
<script lang="ts" setup>
import { onMounted } from "@vue/runtime-core"
import Collapse from "bootstrap/js/dist/collapse"
onMounted(() => {
new Collapse(document.body)
})
</script>
<template>
<div>
<slot></slot>
</div>
</template>
I get this error: ReferenceError: document is not defined
. On nuxt, you could do,
onMounted(() => {
if(process.client) {
new Collapse(document.body)
}
})
How do I do the same?
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Bootstrap throws error 'ReferenceError: document is not defined'
If we directly import JS like CSS we will run into error which would say window and document is not defined. This is...
Read more >Document is not defined Javascript - Stack Overflow
You're getting this error because you're running JavaScript in the server-side Node environment where the DOM ( document , window , etc) isn't ......
Read more >ReferenceError: document is not defined in JavaScript
To solve the"ReferenceError: document is not defined" error, make sure to only use the document global variable on the browser. The variable relates...
Read more >How to solve the document is not defined error - Flavio Copes
Here's how to fix the “referenceerror: document is not defined” error that you might have in Node.js or with a tool like Next.js....
Read more >Fixing Next js "ReferenceError: document is not defined"
The error is thrown because document is only available inside the browser and not on the server. Next js executes this code on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Makes sense.
Yeah but that will include the whole bootstrap js file. I only needed some components. So did the lazy loading js way.