Comments (8)
This worked for me (combination of answers before):
In nuxt.config.ts:
build: {
transpile: ['gsap']
}
in app.vue:
<script setup lang="ts">
import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger)
function addScrollClass() {
ScrollTrigger.create({
// markers: true,
start: '200px top',
trigger: 'body',
toggleClass: { targets: '.navbar-main', className: 'is-scrolled' },
})
}
onMounted(() => {
addScrollClass()
})
</script>
from framework.
Is it works for you?
import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger)
from framework.
No, same error all around.
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import { ScrollTrigger } from 'gsap/dist/ScrollTrigger';
import ScrollTrigger from 'gsap/ScrollTrigger';
import ScrollTrigger from 'gsap/dist/ScrollTrigger';
// all do not work
// only
import { ScrollTrigger } from 'gsap/ScrollTrigger.js';
import { ScrollTrigger } from 'gsap/dist/ScrollTrigger.js';
import ScrollTrigger from 'gsap/ScrollTrigger.js';
import ScrollTrigger from 'gsap/dist/ScrollTrigger.js';
// runs in production (build is fine, it's a runtime error)
from framework.
We may be able to improve this experience in dev (resolving to the id with .js
).
But the core of this is a packaging issue with gsap
: see https://v3.nuxtjs.org/concepts/esm. You could likely resolve by adding it to your build.transpile
array.
from framework.
I tried it, this is the error I got:
self is not defined
at file://./.nuxt/dist/server/server.mjs:7504:22
at $id_e82c9c8c (file://./.nuxt/dist/server/server.mjs:7505:
at __instantiateModule__ (file://./.nuxt/dist/server/server.
at __ssrLoadModule__ (file://./.nuxt/dist/server/server.mjs:
at ssrImport (file://./.nuxt/dist/server/server.mjs:10125:13
at $id_49eb7661 (file://./.nuxt/dist/server/server.mjs:1784:
at async __instantiateModule__ (file://./.nuxt/dist/server/s
m.default is not a function
at file://./.nuxt/dist/server/server.mjs:10:126
at processTicksAndRejections (node:internal/process/task_que
at async renderToString (file://./node_modules/vue-bundle-re
at async renderMiddleware (file://./.nuxt/nitro/index.mjs:20
at async handle (file://./node_modules/h3/dist/index.mjs:601
from framework.
Right now my solution for that is to use the script version of it like this in the nuxt.config.js/ts
Also gsap is recommending this kind of, because the probability is high, that your user has already downloaded the script from another site. Downside is of course, if you only need in some specific components, but then you could also load it with useMeta there.
meta: {
script: [
{ src: "https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js" },
{
src: "https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/ScrollTrigger.min.js",
},
],
},
from framework.
@chrispreisler I would say that this solution just goes back to the first issue that I have with ScrollTrigger. I need TS support, and that doesn't work if I import the js file. ScrollTrigger works perfectly otherwise.
from framework.
@StevenJPx2 you are correct, sorry I overread your need for TS support.
from framework.
Related Issues (20)
- how to use obfuscator on nuxt3
- Accessibility of API return
- Migration to `nuxt/nuxt` HOT 1
- Dependency Dashboard
- [FEATURE REQUEST] Preview mode for Nuxt 3 HOT 1
- ContentResolver fails when using nuxt rc12 or newer HOT 1
- onResponseError
- about middleware and logs collection HOT 1
- Place of the nitro server in Techempower Web Framework Benchmarks HOT 1
- Postcss with Nuxt 3.0.0 HOT 1
- Never use browser cache in https access
- Playwright chromioum works in dev but fails on production
- How to get access localStorage Nuxt.config.ts version 3?
- How can i get the response headers on the client side? HOT 1
- How to add a cache policy HOT 1
- Help: How to use App.vue and wait for store to be ready through the app
- HMR won't connect behind reverse proxy with Firefox HOT 2
- Windows-IIS-Server
- vite watch is not working in node_modules directory. HOT 1
- Server directory documentation about SSR requests and performance with nuxt
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from framework.