-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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: Unexpected token 'export' with Next.js #24481
Comments
Thanks for the issue! This issue has been labeled as In the meantime, please read our Winter Holiday Triage Guide for information on how to ensure that your issue is triaged correctly. Thank you! |
Thanks for the issue. Can you please reproduce this in a GitHub repo and provide a link to it? |
@liamdebeasi Here is a repo where I was able to reproduce the issue with a brand new Next.js app using create-next-app, and added the Ionic 6 modules. |
Thanks! I am getting the following error:
I tried the suggestion on the link included in the error, but no luck. Any ideas? |
Can you try removing the package-lock.json and yarn.lock files and the node modules and try again? There may be a module I have locked in that doesn't work with your system. |
Thanks! The issue here appears to be related to the default behavior of Next.js, not Ionic: https://stackoverflow.com/questions/65936222/next-js-syntaxerror-unexpected-token-export By default Next.js transpiles ES6 code in the The recommended approach on vercel/next.js#32223 seems to be to use https://www.npmjs.com/package/next-transpile-modules. Your const withTM = require('next-transpile-modules')(['@ionic/react', '@ionic/core', '@stencil/core', 'ionicons']);
/** @type {import('next').NextConfig} */
module.exports = withTM({
reactStrictMode: true,
}); However, in doing that you will likely get a Can you try the |
I had some free time and fixed the window error in: #24603. There appears to be a lingering issue with Ionicons, and I am looking at that separately. |
I fixed the window and Ionicons issues. I also created a dev build with the fixes if you are interested in testing that alongside the
|
@liamdebeasi I've also been trying to get Ionic and Next.js working again since this broke in the early v6 betas. With your latest fixes + transpiling, it's almost working! It now compiles, but there's a runtime error now when trying to use an ion-icon:
If I remove the use of My reproduction repo here: https://github.com/Polarisation/ionic-next-js |
I have applied your fixes in next.config.js, and am using your dev version of @ionic/react. I am now getting an errors with ion-icon as well. I've pushed the changes I made to the same repo so you can try as well. It looks like I'm getting a completely different error in that one. |
One thing to note, my actual project (not the demo project I shared) is working with these same changes, as long as I remove the call to |
Can you update to Ionicons 6.0.1 in your project? That icon issue should be fixed. The |
Ionicons 6.0.1 does not fix the runtime error I listed in #24481 (comment) This error is not blocking me from using Ionic with Next.js, since I'm not using IonIcons myself, however it would be beneficial for Ionic to fix this as my reproduction repo is adapted directly from the Ionic example app provided by Next.js (generated with |
The issue mentioned in #24481 (comment) is caused by ionic-team/stencil#3208. We are definitely interested in resolving this and are working closely with the Stencil team. |
Thanks for the issue. This has been resolved via #24604 and #24603, and a fix will be available in an upcoming release of Ionic Framework. We are still working on the issue mentioned in #24481 (comment) and will track that in ionic-team/stencil#3208. |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Prerequisites
Ionic Framework Version
Current Behavior
When updating to Ionic 6 and trying to run the app, I get this error,
ServiceError: Unexpected token 'export'
.Previously, my app was using Ionic 5 with Next.js. Following the guidelines to migrate to Ionic 6, The only thing I've changed was to add the
setupIonicReact()
call as noted as required in v6. Without adding this call, the app still fails to load. The same error just manifests differently.Expected Behavior
Expected to update from Ionic 5 to Ionic 6 and still run successfully.
Steps to Reproduce
Add Ionic 6 to Next.js project.
Code Reproduction URL
No response
Ionic Info
I am not using Ionic CLI for anything as this is a Next.js app. I am only using Ionic as a UX framework.
Additional Information
As mentioned, I am not using Ionic CLI for anything as this is a Next.js app. I am only using Ionic as a UX framework. I am trying to use
@ionic/react
for styling and components only.The text was updated successfully, but these errors were encountered: