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.

GSAP ScrollTrigger cannot be imported as module in build

See original GitHub issue

Environment

Nuxt CLI v3.0.0-27383920.81ee59c Nuxt project info:


  • Operating System: Darwin
  • Node Version: v17.3.1
  • Nuxt Version: 3.0.0-27383920.81ee59c
  • Package Manager: yarn@1.22.15
  • Bundler: Vite
  • User Config: build
  • Runtime Modules: -
  • Build Modules: -

Reproduction

npm i gsap

<script setup lang="ts">
import {gsap} from 'gsap'
// even though importing gsap like "import gsap from 'gsap'"
// is valid, it throws the error gsap.registerPlugin is not a function
// when running the production build
import ScrollTrigger from 'gsap/dist/ScrollTrigger'
// over here, the error is "Did you mean to import gsap/dist/ScrollTrigger.js?"
// Once it's done, it works, but there no longer is any typescript support
gsap.registerPlugin(ScrollTrigger)
</setup>

Describe the bug

Build errors

Additional context

No response

Logs

No response

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Zielgestaltcommented, Feb 7, 2022

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>
0reactions
chrispreislercommented, Jan 28, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems importing ScrollTrigger - GSAP - GreenSock
I'm confused about how to import ScrollTrigger into my svelte app. I tried: ... Cannot use import statement outside a module
Read more >
Getting error `Cannot use import statement outside a module ...
This is a common issue for frameworks that do SSR because of past limited support for ES Modules in a node environment. import...
Read more >
GSAP 3.10.3 not importing ScrollTrigger/ ScrollSmoother ...
I am importing in gsap, ScrollTrigger & ScrollSmoother but I am getting ... Have you tried importing the UMD modules from the dist...
Read more >
Import ERROR with ScrollTrigger in Next JS - GSAP
whenever I use on simple GSAP it works brilliant in NEXT JS but with ScrollTrigger it gives an import error. My code is:...
Read more >
Unable to import plugins... - GSAP - GreenSock
Hey, Whenever I try to import a plugin the build fails with this ... module' (758:0) while parsing /node_modules/gsap/ScrollTrigger.js while ...
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