-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] SyntaxError: Cannot use import statement outside a module, NEXTJS 13 #6525
Comments
以下的 Issues 可能会帮助到你 / The following issues may help you
|
Please help me solve this problem |
I guess there is an exception during publish, which caused an es import in cjs module. When I rebuild library, it outputs correctly. |
Issue is still have. Pls help |
I have the same problem |
|
Did u visit /about page? Error occurs there |
very sad, seems like it wont be fixed. |
Yeah it wont be fixed but I installed sub component instead of @ant-design/pro-components |
same problem |
|
also having this issue... |
have same issue - import Content from 'components/pages/Course/Content'
+ import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
+ const Content = dynamic(async () => await import('components/pages/Course/Content'), {
+ ssr: false,
+ })
function ContentPage() {
return <Content />
}
export default ContentPage what interesting - in my project i have 5 places where |
From my part, I was able to solve this thanks to the response from @ogienma at #4852 (comment) in Next.js v13 with Ant Design v5. |
Great to hear that the issue is resolved for you! Could you please share the solution you used in case others encounter similar issues in the future? Thank you! |
Server Error |
maybe antd-pro is for internal, recommend to make your own pro by using antd. 😃 |
I have the same one |
same to me . |
The error message "SyntaxError: Cannot use import statement outside a module" typically occurs in a Next.js 13 project when you're trying to use an import statement in a file that is not recognized as a module. In Next.js 13, you need to use the To resolve this issue, you can try the following steps:
By following these steps, you should be able to resolve the "SyntaxError: Cannot use import statement outside a module" issue in Next.js 13. |
you can use transpilePackages |
When you encounter "SyntaxError: Unexpected token 'export'", "'SyntaxError: Cannot use import statement outside a module'" and other related issues, you need to add the module that exposes the issue to the transpilePackages configuration.
|
The same error was happening to me, my import was like this:
so I changed it to:
and incredibly the webpack error was resolved. |
why? |
When you import a module using "antd", webpack looks for the module in the "node_modules" directory and then resolves it based on the main entry point specified in the "package.json" file of the "antd" package. This main entry point could be a JavaScript file or a directory. In contrast, when you import a module using "antd/lib", webpack directly targets the specific file or directory within the "antd" package without relying on the main entry point specified in "package.json". This can sometimes resolve issues related to how webpack resolves module paths or handles specific files. |
🐛 About Error
Next 13 framework is used, there was an attempt to use pro ant components, unfortunately I get an error, for more details, look at the codesandbox
SyntaxError: Cannot use import statement outside a module
/node_modules/antd/es/skeleton/style/index.js (1)
📷 Problem reproduction
https://shortest.link/drl5
Go to /about page
🏞 Desired result
Display components without errors
💻 播放代碼
https://shortest.link/drl5
Go to /about page
© package.json
The text was updated successfully, but these errors were encountered: