jnemec Posted April 1, 2023 Share Posted April 1, 2023 I've done another project using GSAP in Next.js, but I had zero issues with importing. I started a new project and now I'm getting "SyntaxError: Cannot use import statement outside a module". I've tried importing using gsap/dist/ScrollTrigger and it removes the error but then ScrollTrigger doesn't work at all. I'm certain I set up my other project the same way, so I'm really confused. My content is in the "components" folder. https://codesandbox.io/p/sandbox/staging-resonance-szbojy?file=%2Fcomponents%2FBody.tsx&selection=[{"endColumn"%3A23%2C"endLineNumber"%3A18%2C"startColumn"%3A23%2C"startLineNumber"%3A18}] Link to comment Share on other sites More sharing options...
GreenSock Posted April 2, 2023 Share Posted April 2, 2023 It seems to work fine for me when I import from the UMD files: import { gsap } from "gsap/dist/gsap"; import { ScrollTrigger } from "gsap/dist/ScrollTrigger"; Are you saying that doesn't work for you? Link to comment Share on other sites More sharing options...
onKeyBoard Posted June 10, 2023 Share Posted June 10, 2023 This does seem to be an often-reported issue wherever Next.js and ScrollTrigger are used together. If you know your project setup supports ES modules but ScrollTrigger is still causing Next to report the "SyntaxError: Cannot use import statement outside a module" error, try adding this to your next.config.js : module.exports = { transpilePackages: ['gsap'], /* Your Next.js config */ }; 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now