Git Product home page Git Product logo

Comments (8)

Zielgestalt avatar Zielgestalt commented on May 22, 2024 1

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.

franzus5 avatar franzus5 commented on May 22, 2024

@StevenJPx2

Is it works for you?

import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';

gsap.registerPlugin(ScrollTrigger)

from framework.

StevenJPx2 avatar StevenJPx2 commented on May 22, 2024

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.

danielroe avatar danielroe commented on May 22, 2024

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.

StevenJPx2 avatar StevenJPx2 commented on May 22, 2024

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.

chrispreisler avatar chrispreisler commented on May 22, 2024

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.

StevenJPx2 avatar StevenJPx2 commented on May 22, 2024

@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.

chrispreisler avatar chrispreisler commented on May 22, 2024

@StevenJPx2 you are correct, sorry I overread your need for TS support.

from framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.