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

[Next.js] basePath should be / when using a custom URL #67

Open
TimPietrusky opened this issue Feb 14, 2023 · 7 comments
Open

[Next.js] basePath should be / when using a custom URL #67

TimPietrusky opened this issue Feb 14, 2023 · 7 comments

Comments

@TimPietrusky
Copy link

When configuring a custom domain for a repository, the basePath for a Next.js app should not include the name of the repo as the root of the website is just /.

Steps to reproduce

  • Configure a custom URL for a repo in Settings > Pages > Custom Domain
  • Deploy the next-app using actions/configure-pages@v3
  • See that none of the resources (like CSS or JS) can be loaded as the basePath is set to reponame

Workaround

To still keep the "disable image optimisation"-option, I forked this action and removed the basePath config, but that is not optimal.

Suggestion

  • Make the basePath configurable and when nothing is configured, it's using the reponame, but a user could overwrite it with / if they want to
  • Update the comment in the provided workflow (nextjs.yml) to make sure that user know that this can be done (but I guess this is not the scope of this repo, pease let me know where this should be fixed)
@JamesMGreene
Copy link
Contributor

Thanks for the report, @TimPietrusky!

Do you happen to have a public repo available where you're running into this issue? 🤔 We haven't seen this behavior ourselves as far as I know, but definitely open to expanding our internal end-to-end tests if we're missing something. 👍🏻

  • Update the comment in the provided workflow (nextjs.yml) to make sure that user know that this can be done (but I guess this is not the scope of this repo, pease let me know where this should be fixed)

The Next.js starter workflow template that GitHub suggests can be found in the actions/starter-workflows repo:
actions/starter-workflows@pages/nextjs.yml

@JamesMGreene
Copy link
Contributor

One debugging step that would also help is to check what Pages site URL is being detected by the Action. This would help narrow down if the issue is in the values returned by the Pages REST API, a bug in our injection code, or some incompatibility between your Next.js config and our injection code.

To debug, update your Actions workflow with a few changes like the following:

      # Find your existing step for this, then add an `id` property
      - name: Setup Pages
        id: pages
        uses: actions/configure-pages@v3
        with:
          static_site_generator: next
      - name: Dump Pages configuration
        run: |
          echo PAGES_BASE_URL:  ${{ steps.pages.outputs.base_url }}
          echo PAGES_ORIGIN:    ${{ steps.pages.outputs.origin }}
          echo PAGES_HOST:      ${{ steps.pages.outputs.host }}
          echo PAGES_BASE_PATH: ${{ steps.pages.outputs.base_path }}

Although I'd like to fix whatever issue you're running into, it's probably also worth mentioning that you could probably use the aforementioned outputs values as a short-term workaround to, say, set environment variables for the duration of the workflow run that could then be used within your next.config.js when building/exporting your Next.js site. 💡

@REDDOT007
Copy link

ok

@TimPietrusky
Copy link
Author

@JamesMGreene thanks for your message!

The public repo where I was running into this is: https://github.com/iieinander/iieinander.band

Is there anything else that you need?

@JamesMGreene
Copy link
Contributor

@TimPietrusky What I'm seeing in your Actions logs would suggest that the basePath is being set to "", which is the expected value for Next.js when there isn't any notable base path (trailing slashes are excluded). 🤔

https://github.com/iieinander/iieinander.band/actions/runs/4173980364/jobs/7226978361#step:5:58

Extra line breaks added for legibility:

Found configuration object in indirect module export
Injection successful, new configuration:
/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {unoptimized: true},
  experimental: {images: {unoptimized: true}},
  basePath: "",
  reactStrictMode: true,
  swcMinify: true,
};

module.exports = nextConfig;

@TimPietrusky
Copy link
Author

@JamesMGreene yes, this is true, but only because I'm using my fork. When I used the original action, the basePath was set:

https://github.com/iieinander/iieinander.band/actions/runs/4166191535/jobs/7210202546#step:5:58

const nextConfig = {
  images: {unoptimized: true},experimental: {images: {unoptimized: true}},basePath: "/iieinander.band",reactStrictMode: true,
  swcMinify: true,
};

In my fork TimPietrusky@f294021, I commented out the basePath, so it's never set.

@tyliec
Copy link

tyliec commented Jan 23, 2024

Noting that we ran into this same issue at https://github.com/CodeWithAloha/CWAWebsite, more info at CodeWithAloha/website#51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants