the-supersonic-plugin-for-scroll-based-animation icon indicating copy to clipboard operation
the-supersonic-plugin-for-scroll-based-animation copied to clipboard

Nextjs module not found: Can't resolve 'the-supersonic-plugin-for-scroll-based-animation'

Open aboutjquery opened this issue 1 year ago • 6 comments

Hello, this plugin is great, but I have a problem and can't import the plugin I'm using nextjs, below is the code

import {
 TheSupersonicPlugin,
} from 'the-supersonic-plugin-for-scroll-based-animation';
 new TheSupersonicPlugin([
 {
 start: '.start',
 end: '.end',
 elements: ['.animatable-element'],
 },
 ]);

What is the reason? I have installed the plug-in correctly.

Thanks.

aboutjquery avatar Jul 19 '24 15:07 aboutjquery

@aboutjquery Can you give a screenshot or error code?

the-illarionov avatar Jul 19 '24 15:07 the-illarionov

@aboutjquery Can you give a screenshot or error code?

Build Error
Failed to compile

Module not found: Can't resolve 'the-supersonic-plugin-for-scroll-based-animation'
  1 | import { useTranslations } from 'next-intl';
  2 | import Container from 'react-bootstrap/Container';
> 3 | import { TheSupersonicPlugin } from 'the-supersonic-plugin-for-scroll-based-animation';
    | ^
  4 |
5 | const plugin = new TheSupersonicPlugin([
  6 |   {

Hi, that is the error code, thanks.

aboutjquery avatar Jul 21 '24 22:07 aboutjquery

@aboutjquery it looks like you haven't installed the plugin via npm install the-supersonic-plugin-for-scroll-based-animation --save-dev

the-illarionov avatar Jul 22 '24 06:07 the-illarionov

@aboutjquery it looks like you haven't installed the plugin via npm install the-supersonic-plugin-for-scroll-based-animation --save-dev

I have already installed

"the-supersonic-plugin-for-scroll-based-animation": "^2.1.0"

I have no idea why its happen.

aboutjquery avatar Jul 22 '24 07:07 aboutjquery

@aboutjquery i'm not super familiar with nextjs, but if you can locate the-supersonic-plugin-for-scroll-based-animation in your node_modules folder, a possible reason maybe is that nextjs tries to execute plugin in SSR mode and it fails, because plugin relies on browser API, which is not available in SSR mode. I would try to import plugin dynamically like here.

Please return with an answer if it helps.

the-illarionov avatar Jul 22 '24 07:07 the-illarionov

@aboutjquery i'm not super familiar with nextjs, but if you can locate the-supersonic-plugin-for-scroll-based-animation in your node_modules folder, a possible reason maybe is that nextjs tries to execute plugin in SSR mode and it fails, because plugin relies on browser API, which is not available in SSR mode. I would try to import plugin dynamically like here.

Please return with an answer if it helps.

Thanks and sorry for my late reply, I am using SSG now, and I tried:


const TheSupersonicPlugin = dynamic(
  () =>
    import('the-supersonic-plugin-for-scroll-based-animation').then(
      (mod) => mod.TheSupersonicPlugin,
    ),
  { ssr: false },
);

Error report

Module not found: Can't resolve 'the-supersonic-plugin-for-scroll-based-animation'
  14 | const TheSupersonicPlugin = dynamic(
  15 |   () =>
> 16 |     import('the-supersonic-plugin-for-scroll-based-animation').then(
     |     ^

I am no idea why its happen.

aboutjquery avatar Aug 10 '24 13:08 aboutjquery