Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

398
Views
Next js: Cannot use import statement outside a module

I'm trying to use 'hover-effect' library in my next js application. However, I'm getting these error:

Server Error => SyntaxError: Cannot use import statement outside a module (/node_modules/gsap/TweenMax.js (14))

Code:

import { Container, Header } from '../components';
// @ts-ignore
import hoverEffect from 'hover-effect';
import { useEffect } from 'react';

    const Home = () => {
      useEffect(() => {
        new hoverEffect({
          parent: document.querySelector('.landing-page-slider'),
          intensity: 0.3,
          image1: 'images/slider-img1.jpg',
          image2: 'images/slider-img2.jpg',
          displacementImage: 'images/displacement/1.jpg',
        });
      }, []);
      return (
        <Container>
          <Header />
          <div className="landing-page-slider"></div>
        </Container>
      );
    };
    
    export default Home;

Things I tried:

const hoverEffect: any = dynamic(() => import('hover-effect'), { ssr: false });

then error becomes: TypeError: hoverEffect is not a constructor

I added "type":"module" in package.json file then error becomes:

Failed to load next.config.js. ReferenceError: module is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension.To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

And now I cannot start server until I removed "type":"module" in package.json. Is there any way to use this library in next js app?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!