RocketCommunicationsInc / astro

Astro UXDS is a collection of guidelines, patterns and components for designing space-based user interface applications.
https://astrouxds.com
Other
108 stars 25 forks source link

(React) SyntaxError: Unexpected token 'export' #1174

Closed jm-bh closed 1 year ago

jm-bh commented 1 year ago

Describe the bug When importing components into a Next.js (React framework) app, Astro throws SyntaxError: Unexpected token 'export'.

To Reproduce Steps to reproduce the behavior:

  1. Create a new Next app yarn create next-app
  2. Install Astro yarn add @astrouxds/react
  3. Add the CSS in pages/_app.tsx
  4. Use an Astro component on any page
  5. Error

Current behavior While rendering, a SyntaxError is thrown. The error comes from @astrouxds/react/dist/index.js:1: export * from "./components";

Expected behavior No error

Screenshots image image

CodeSandbox View the problem on StackBlitz

Environment (please complete the following information):

Additional context n/a

jm-bh commented 1 year ago

Turns out this is an issue with Next.js, not Astro. Sorry about that!

For anyone else that runs into this issue, you need to use the transpilePackages option in next.config.js:

{
  ...

  transpilePackages: [
    '@astrouxds/react',
    '@astrouxds/astro-web-components',
  ],
}
micahjones13 commented 1 year ago

That's a good gotcha, we'll throw that in our docs. Thanks for letting us know!