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

"Top-level return cannot be used inside an ECMAScript module" #5922

Closed
1 task
jyasskin opened this issue Jan 21, 2023 · 2 comments · Fixed by #6036
Closed
1 task

"Top-level return cannot be used inside an ECMAScript module" #5922

jyasskin opened this issue Jan 21, 2023 · 2 comments · Fixed by #6036
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@jyasskin
Copy link
Contributor

What version of astro are you using?

1.9.2

Are you using an SSR adapter? If so, which one?

Node

What package manager are you using?

npm

What operating system are you using?

Linux

Describe the Bug

I'm getting a "Top-level return cannot be used inside an ECMAScript module" error. When trying to reduce the error, it appears to go away once I simplify the surrounding code enough, so I suspect it's caused by the presence of another error. However, that means the real error is replaced by this incorrect one, which makes it hard to fix the other error. See the stackblitz below for the complex reproduction.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-hz21xe?file=src/pages/[...crawl_date].astro

Participation

  • I am willing to submit a pull request for this issue.
@jyasskin
Copy link
Contributor Author

And, in fact, this one was caused by an underlying error on the await inside the page template. So the bug isn't that the page should work, but that it should show the right error.

@matthewp matthewp added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Jan 26, 2023
natemoo-re added a commit that referenced this issue Jan 30, 2023
@foodelevator
Copy link

foodelevator commented Mar 26, 2023

I get this error from the following code:

return new Response(null, {
    status = 401,
});

When running node, I get this error (which should probably be the same in this case):

Uncaught SyntaxError: Invalid shorthand property initializer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants