react-tweet icon indicating copy to clipboard operation
react-tweet copied to clipboard

Module parse failed: Cannot use 'import.meta' outside a module

Open dillionverma opened this issue 2 years ago • 9 comments

image

- error ./node_modules/react-tweet/node_modules/@babel/runtime/helpers/interopRequireDefault.js
Module parse failed: Cannot use 'import.meta' outside a module (39:16)
|                 // still a Refresh Boundary later.
|                 // @ts-ignore importMeta is replaced in the loader
>                 import.meta.webpackHot.accept();
|                 // This field is set when the previous version of this module was a
|                 // Refresh Boundary, letting us know we need to check for invalidation or


Getting the following error while running.

package.json:


    "eslint-config-next": "^13.4.2",
    "next": "^13.4.2",
    "next-auth": "^4.22.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-tweet": "^2.0.1",

dillionverma avatar May 17 '23 22:05 dillionverma

@dillionverma Can you provide a reproduction 🙏

lfades avatar Jun 26 '23 17:06 lfades

@lfades Hitting the same limitation. SWC is disabled for our project because we rely on babel for a library. I tried to create a reproduction online but couldn't. This is what I was trying -> https://codesandbox.io/p/sandbox/angry-robinson-sk8mrv?file=%2Fpackage.json%3A22%2C36. Basically just added a .babelrc.js similar to our current setup so that next disables SWC on detecting it but I can see atleast the loader of the Tweet component coming. Whereas, in our local dev, we are getting the same error like so :- Screenshot 2023-07-27 at 3 57 00 PM

We are using the latest version i.e. 13.4.12

Any clue as to what might be happening here ?

lakbychance avatar Jul 27 '23 10:07 lakbychance

Looks like it's something with babel when used in Next.js. The package output of react-tweet does not use import.meta and all files are modules. Did you also add reac-tweet to transpilePackages? although I'm not entirely sure if that one works with babel.

lfades avatar Jul 27 '23 22:07 lfades

Looks like it's something with babel when used in Next.js. The package output of react-tweet does not use import.meta and all files are modules. Did you also add reac-tweet to transpilePackages? although I'm not entirely sure if that one works with babel.

Yup the transpilePackages is already added to next.config.js

lakbychance avatar Jul 28 '23 12:07 lakbychance

Getting this issue as well.

jshwrnr avatar Jul 31 '23 13:07 jshwrnr

Hey everyone! I'm also getting this issue, does anyone have an ideia why this is happening?

reabreu avatar Aug 29 '23 09:08 reabreu

So I resolved this for myself by using app router instead (Nextjs 13).

Not a feasible solution for everyone but just wanted to let people know

dillionverma avatar Sep 01 '23 17:09 dillionverma

Hey, thanks for the feedback!

reabreu avatar Sep 03 '23 08:09 reabreu

I solved the problem by adding

"resolutions": {
  "@babel/runtime": "^7.24.6"
},

to my package.json. As explained in this issue

timbicker avatar Jul 15 '24 14:07 timbicker