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

undefined params within getStaticPaths cause Vercel build to fail #6095

Closed
1 task
joe-bell opened this issue Feb 2, 2023 · 7 comments · Fixed by #6353
Closed
1 task

undefined params within getStaticPaths cause Vercel build to fail #6095

joe-bell opened this issue Feb 2, 2023 · 7 comments · Fixed by #6353
Labels
- P2: has workaround Bug, but has workaround (priority)

Comments

@joe-bell
Copy link
Sponsor Contributor

joe-bell commented Feb 2, 2023

What version of astro are you using?

2.0.0

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

Vercel

What package manager are you using?

pnpm

What operating system are you using?

Mac

Describe the Bug

Expectation

When using params in a getStaticPaths function, I would expect undefined to result in the creation of an index route.

Actual Behaviour

The build fails in Vercel

Success: Without undefined params
19:36:18.324	▶ src/pages/example/[...slug].astro
19:36:18.345	  ├─ /example/one/index.html (+21ms)
19:36:18.347	  ├─ /example/two/index.html (+23ms)
19:36:18.348	  └─ /example/three/index.html (+25ms)
19:36:18.349	λ src/pages/api/example/[...slug].ts
19:36:18.350	  ├─ /api/example/one (+1ms)
19:36:18.351	  ├─ /api/example/two (+2ms)
19:36:18.351	  └─ /api/example/three (+3ms)
19:36:18.351	Completed in 59ms.
Error: With undefined params
▶ src/pages/example/[...slug].astro
19:39:10.815	  ├─ /example/one/index.html (+18ms)
19:39:10.817	  ├─ /example/two/index.html (+19ms)
19:39:10.818	  ├─ /example/three/index.html (+21ms)
19:39:10.820	  └─ /example/index.html (+22ms)
19:39:10.820	λ src/pages/api/example/[...slug].ts
19:39:10.821	  ├─ /api/example/one (+1ms)
19:39:10.822	  ├─ /api/example/two (+2ms)
19:39:10.822	  ├─ /api/example/three (+3ms)
19:39:10.911	 error   EISDIR: illegal operation on a directory, open '/vercel/path0/.vercel/output/static/api/example'
19:39:10.911	Error: EISDIR: illegal operation on a directory, open '/vercel/path0/.vercel/output/static/api/example'
19:39:10.926	 ELIFECYCLE  Command failed with exit code 1.

Link to Minimal Reproducible Example

https://github.com/joe-bell/astro-bug-params-undefined

Note

More details have been provided in the reproduction

Participation

  • I am willing to submit a pull request for this issue.

Not part of the template, but just want to say a huge thanks to the Astro team – I love using this product and I appreciate you all!

@AirBorne04
Copy link
Contributor

Ok there seems to be an inconsistency with the behaviour between API routes and Pages where for Pages undefined is translated into index, for the API routes undefined is throwing an error and not falling back to index.
The easy work around would be to add index for the API route directly.

@AirBorne04 AirBorne04 added the - P2: has workaround Bug, but has workaround (priority) label Feb 2, 2023
@joe-bell
Copy link
Sponsor Contributor Author

joe-bell commented Feb 2, 2023

Cheers! That’s the tactic I’ve opted for now; with a _handler.ts that’s used across both index.ts and […slug].ts

It’s fine in the meantime, but of course would be nice to have matching behaviour across all routes

@joe-bell
Copy link
Sponsor Contributor Author

joe-bell commented Feb 3, 2023

Following up: It seems like this workaround unfortunately doesn't work

The index.ts builds, but the [slug] or [...slug] doesn't:

λ src/pages/example/index.ts
--
17:26:26.181 | └─ /assets/example (+16ms)
17:26:26.181 | λ src/pages/example/[slug].ts
17:26:26.495 | error   ENOTDIR: not a directory, mkdir '/vercel/path0/.vercel/output/static/example/'

@AirBorne04
Copy link
Contributor

Sorry I might not have been clear on what I meant exactly, you do not need to create a separate index.ts.

My suggestion was to replace this line:

const slugs = ["one", "two", "three", undefined];

with the following

const slugs = ["one", "two", "three", "index"];

@AirBorne04
Copy link
Contributor

AirBorne04 commented Feb 11, 2023

Hi @joe-bell,
it seems that example/works just example not. I would like to dig deeper on this one, but I do not have time at the moment.
@matthewp can you check this out?

@JerryWu1234
Copy link
Contributor

JerryWu1234 commented Feb 22, 2023

Thanks @AirBorne04!

That seems to work for endpoints, but not for regular pages

joe-bell/astro-bug-params-undefined#1

i wan to check out, but I feel like i'm missing out on something.
this link of code all from this https://github.com/joe-bell/astro-bug-params-undefined repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants