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

Experimental redirect: "Failed to resolve entry for package" #7478

Closed
1 task
sanderbongers opened this issue Jun 25, 2023 · 4 comments · Fixed by #7644
Closed
1 task

Experimental redirect: "Failed to resolve entry for package" #7478

sanderbongers opened this issue Jun 25, 2023 · 4 comments · Fixed by #7644
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@sanderbongers
Copy link

What version of astro are you using?

2.7.0

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

No

What package manager are you using?

pnpm (but happens with all)

What operating system are you using?

Mac

What browser are you using?

Firefox

Describe the Bug

My aim is to use /blog as the homepage instead of /, which I tried using aredirect, like this:

astro.config.mjs

export default defineConfig({
	experimental: {
		redirects: true,
	},
	redirects: {
		"/": "/blog",
	},
});

But whenever the redirect key is "/" or "", the build fails (node v20.3.0):

09:28:38 PM [build] Building static entrypoints...
[@astro/plugin-build-internals] Failed to resolve entry for package "/usr/local/var/www/blog". The package may have incorrect main/module/exports specified in its package.json.
 error   Failed to resolve entry for package "/usr/local/var/www/blog". The package may have incorrect main/module/exports specified in its package.json.
  File:
    /usr/local/var/www/blog/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:23382:11
  Code:
    23381 | function packageEntryFailure(id, details) {
    > 23382 |     throw new Error(`Failed to resolve entry for package "${id}". ` +
            |           ^
      23383 |         `The package may have incorrect main/module/exports specified in its package.json` +
      23384 |         (details ? ': ' + details : '.'));
      23385 | }
  Stacktrace:

pnpm run dev works though, it's only pnpm run build that fails.

I've implemented a workaround by using a double slash, like so: "//": "/blog", then it behaves as expected.

What's the expected result?

Being able to build the site with the intended redirect.

Link to Minimal Reproducible Example

https://stackblitz.com/github/withastro/astro/tree/latest/examples/blog?file=astro.config.mjs&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@bluwy bluwy added the - P3: minor bug An edge case that only affects very specific usage (priority) label Jun 26, 2023
@JerryWu1234
Copy link
Contributor

let me take a look

@JerryWu1234
Copy link
Contributor

because '/' was occupied by the vite.
I want to add the '/' after the '/' if the user has used '/' as a redirect path.but I feel that it's maybe not a good idea. I'm afraid of my work being useless.
could you share you idea ,if you are available

@awcot
Copy link

awcot commented Jul 12, 2023

Similar config & goals, same issue

@matthewp matthewp self-assigned this Jul 12, 2023
matthewp added a commit that referenced this issue Jul 13, 2023
matthewp added a commit that referenced this issue Jul 13, 2023
* Update redirects static generation based on recs

Got some great recommendations on how to handle our HTML written
redirect code based on SEO best practices.

See withastro/roadmap#466 (comment)

This implements them all.

* Fix for using the root path / as a redirect

Fixes #7478

* Fix static redirects prefer over dynamic page

Fixes #7581
@sanderbongers
Copy link
Author

Great work @matthewp! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants