Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Doesn't work in NextJS #26

Open
SaadBazaz opened this issue Mar 29, 2023 · 9 comments · May be fixed by #28
Open

[Bug] Doesn't work in NextJS #26

SaadBazaz opened this issue Mar 29, 2023 · 9 comments · May be fixed by #28

Comments

@SaadBazaz
Copy link

SaadBazaz commented Mar 29, 2023

I get the following error on fresh install and importing it in a NextJS page:
SyntaxError: Cannot use import statement outside a module

My import code:

import { Tilt } from 'react-tilt';

Environment:
"next": "13.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",

@Justkanye
Copy link

I got the same error as well. Have you been able to get a solution yet?

@SaadBazaz
Copy link
Author

I got the same error as well. Have you been able to get a solution yet?

I started using the react-parallax-tilt library instead.

@vicarb
Copy link

vicarb commented Apr 25, 2023

im having the same issue

@atenadadkhah
Copy link

Same issue

@karlhorky
Copy link

karlhorky commented May 5, 2023

Yeah it looks like tsup / TypeScript has been incorrectly configured in #23 - not only a problem with Next.js - it indicates a problem generally for the types, including a conflict between:

  1. the type of package being published: CommonJS - no "type": "module" in package.json or anything else to make this package ESM
  2. the type of the source files: ESM, because you can see import keyword there

cc @jonathandion

Check out the Are The Types Wrong? page for react-tilt

Error message:

The implementation resolved at the package uses ESM syntax, but the detected module kind is CJS. This will be an error in Node (and potentially other runtimes and bundlers). The module kind was decided based on the nearest package.json’s lack of a "type": "module" field.

Screenshot 2023-05-05 at 11 11 37

@karlhorky karlhorky linked a pull request May 5, 2023 that will close this issue
@karlhorky
Copy link

@jonathandion since it looks like you want to publish CommonJS instead of ESM (unless you're ready to switch your package to ESM), changing the target in your tsconfig.json to "CommonJS" would be one option.

Opened a PR here:

@ProchaLu
Copy link

ProchaLu commented May 5, 2023

I was able to successfully implement this using the next@13.4.1-canary.1 version and the App Router in the app/ directory. In case you'd like to see a small reproduction project, I've created one on CodeSandbox

Screenshot 2023-05-05 at 11 56 31

@ProchaLu
Copy link

ProchaLu commented May 5, 2023

I encountered the error SyntaxError: Cannot use import statement outside a module while using the pages/ directory in Next.js. I've created a small reproduction project on CodeSandbox to showcase the issue
Screenshot 2023-05-05 at 12 08 55

@miketeix
Copy link

miketeix commented Apr 9, 2024

I added transpilePackages: ["react-tilt"] to my next.config.js to get this to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants