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

Remove "imports on top" warning #1001

Merged
merged 3 commits into from
Jul 21, 2022
Merged

Remove "imports on top" warning #1001

merged 3 commits into from
Jul 21, 2022

Conversation

natemoo-re
Copy link
Member

What kind of changes does this PR include?

  • New or updated content

Description

@netlify
Copy link

netlify bot commented Jul 14, 2022

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit 46ce735
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/62d8c41ef4d6540008a246f5
😎 Deploy Preview https://deploy-preview-1001--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@hippotastic
Copy link
Contributor

hippotastic commented Jul 14, 2022

Does this change also affect the layout property in Markdown files? When translating https://docs.astro.build/en/core-concepts/layouts/#markdown-layouts I was wondering why it said this:

Markdown files can use a special layout property at the top of the frontmatter to specify which .astro component to use as a page layout.

@delucis
Copy link
Member

delucis commented Jul 14, 2022

Does this change also affect the layout property in Markdown files?

I don’t think that was ever impacted by order in the frontmatter? Or if it was, it hasn’t been like that for quite a while.

@sarah11918
Copy link
Member

I don’t think that was ever impacted by order in the frontmatter? Or if it was, it hasn’t been like that for quite a while.

It absolutely affected me, not that long ago, tbh, fwiw!

@delucis
Copy link
Member

delucis commented Jul 14, 2022

It absolutely affected me, not that long ago, tbh, fwiw!

Oh, interesting! Just tried it and definitely doesn’t seem to be the case here: https://stackblitz.com/edit/github-cjkpls?file=src/pages/index.md

Or was this with import inside setup in frontmatter maybe?

@@ -11,16 +11,17 @@ Astro provides several different tools to help you troubleshoot and debug your c

Here are some common error messages you might see in the terminal, what they might mean, and what to do about them.

### Transform failed with X error
### Transform failed with "Unexpected `export`"
Copy link
Member

@sarah11918 sarah11918 Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking, is this exactly how the error message is presented? Quotation marks and code styling? I think we did that before, where the message would read the way it would be seen by the user.

@sarah11918 sarah11918 marked this pull request as draft July 15, 2022 14:19
@sarah11918
Copy link
Member

Marking as draft, since it feels like another free-for-all Friday coming on, and I know this is still blocked upstream!

@delucis delucis marked this pull request as ready for review July 20, 2022 13:26
@delucis delucis added the improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) label Jul 20, 2022
@natemoo-re natemoo-re self-assigned this Jul 20, 2022
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

This message often appears due to a current limitation in Astro requiring your import and export statements to be at the top of your `.astro` file.
A current limitation in Astro is that `export` statements (other than `getStaticPaths()`) are not supported in `.astro` files.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticing that this still doesn’t mention Prop:

Suggested change
A current limitation in Astro is that `export` statements (other than `getStaticPaths()`) are not supported in `.astro` files.
A current limitation in Astro is that `export` statements (other than `getStaticPaths()` and `Props`) are not supported in `.astro` files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this entirely. This limitations was actually removed in withastro/compiler#463. I opened withastro/astro#4003 to provide a better error hint in context for export hoisting issues, since export can cause reference errors. We'll keep an eye out for this and can put that error message here if users have trouble.

An actionable hint is provided in-context via withastro/astro#4003
Comment on lines -14 to -24
### Transform failed with X error

This message often appears due to a current limitation in Astro requiring your import and export statements to be at the top of your `.astro` file.

**Solution**: Write your imports and exports at the top of your component script.

**Status**: Current limitation; fix is being worked on.

**Not sure that this is your problem?**
Check to see if anyone else has reported [this issue](https://github.com/withastro/astro/issues?q=is%3Aissue+is%3Aopen+Transform+failed+with+*+error)!

Copy link
Member Author

@natemoo-re natemoo-re Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this since it's no longer relevant, nor is the Unexpected export error that I originally replaced it with.

withastro/astro#4003 will provide helpful hints in-context if a user does run into an error due to export hoisting

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aww... bye bye TOP NUMBER ONE ERROR. 🥲

@sarah11918
Copy link
Member

I think this LGTM, Nate!

@natemoo-re natemoo-re merged commit 1c90012 into main Jul 21, 2022
@natemoo-re natemoo-re deleted the chore/remove-import-on-top branch July 21, 2022 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants