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

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

Open
jackple opened this issue Dec 29, 2023 · 10 comments
Open

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

jackple opened this issue Dec 29, 2023 · 10 comments
Labels

Comments

@jackple
Copy link

jackple commented Dec 29, 2023

Version of antd-mobile

5.33.2

Operating system and its version

Others

Browser and its version

every

Sandbox to reproduce

No response

What happened?

按照官方的配置https://mobile.ant.design/zh/guide/ssr#nextjs-13
直接在项目中使用

import { Button } from 'antd-mobile'

<Button>aaaaa</Button>

报错:

▲ Next.js 13.5.6

✓ Ready in 3.3s
⨯ ./node_modules/antd-mobile/node_modules/classnames/index.js
Module parse failed: Cannot use 'import.meta' outside a module (93: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

Import trace for requested module:
./node_modules/antd-mobile/node_modules/classnames/index.js
./node_modules/antd-mobile/es/components/action-sheet/action-sheet.js
./node_modules/antd-mobile/es/components/action-sheet/index.js
./node_modules/antd-mobile/es/index.js
○ Compiling / ...
⨯ ./node_modules/antd-mobile/node_modules/classnames/index.js
Module parse failed: Cannot use 'import.meta' outside a module (93: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

Import trace for requested module:
./node_modules/antd-mobile/node_modules/classnames/index.js
./node_modules/antd-mobile/es/components/action-sheet/action-sheet.js
./node_modules/antd-mobile/es/components/action-sheet/index.js
./node_modules/antd-mobile/es/index.js

Relevant log output

No response

@jackple jackple added the bug label Dec 29, 2023
@s875515
Copy link

s875515 commented Mar 6, 2024

Same error, do you have any update?

@jackple
Copy link
Author

jackple commented Mar 9, 2024

@s875515 直接连框架都换了, 不折腾

@s875515
Copy link

s875515 commented Mar 10, 2024

@s875515 直接连框架都换了, 不折腾

哎呀,就是麻煩啊
所以您直接換umijs?

@jackple
Copy link
Author

jackple commented Apr 24, 2024

@s875515 换了vite, umi太重了, 不考虑

@saeedghasemi72
Copy link

same issue with ant design web

@mitya-kocherga
Copy link

mitya-kocherga commented Jun 3, 2024

Any updates on that?
I guess it connected with babel version on your project @jackple
i just struggled with same issue, but changing babel version is helped

@KonomiHayakawa
Copy link

Had the same issue with web version of antd. I had some imports like: ... from 'antd/lib'. Replacing it with ... from 'antd' solved the issue.

@johannespn
Copy link

Getting a similar error when

import { message } from 'antd'

with following stack trace

 ⨯ ./node_modules/antd/node_modules/classnames/index.js
Module parse failed: Cannot use 'import.meta' outside a module (93: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

Import trace for requested module:
./node_modules/antd/node_modules/classnames/index.js
./node_modules/antd/es/message/PurePanel.js
./node_modules/antd/es/message/index.js
__barrel_optimize__?names=message!=!./node_modules/antd/es/index.js

with next: 14.2.3 and antd: 5.19.3. Downgrading next to next: 14.0.2 fixed the issue.

@KaldrArt
Copy link

Getting a similar error when

import { message } from 'antd'

with following stack trace

 ⨯ ./node_modules/antd/node_modules/classnames/index.js
Module parse failed: Cannot use 'import.meta' outside a module (93: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

Import trace for requested module:
./node_modules/antd/node_modules/classnames/index.js
./node_modules/antd/es/message/PurePanel.js
./node_modules/antd/es/message/index.js
__barrel_optimize__?names=message!=!./node_modules/antd/es/index.js

with next: 14.2.3 and antd: 5.19.3. Downgrading next to next: 14.0.2 fixed the issue.

worked! thank you

@bcanedo4
Copy link

bcanedo4 commented Oct 9, 2024

Upgrading the classnames npm package to 2.5.1 fixed it for me.

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

No branches or pull requests

8 participants