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

nuxt3 project cannot be deployed on Github pages #25638

Closed
mesoul2024 opened this issue Feb 5, 2024 · 3 comments
Closed

nuxt3 project cannot be deployed on Github pages #25638

mesoul2024 opened this issue Feb 5, 2024 · 3 comments

Comments

@mesoul2024
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v20.9.0
  • Nuxt Version: 3.9.1
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: npm@10.1.0
  • Builder: -
  • Runtime Modules: @pinia/nuxt@0.5.1, @vueuse/nuxt@10.7.2, nuxt-simple-sitemap@3.4.1, @nuxtjs/robots@3.0.0, nuxt-jsonld@2.0.8, @nuxtjs/tailwindcss@6.10.4, @nuxtjs/google-fonts@3.1.3, @nuxtjs/google-adsense@3.0.0
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-pdjfrq?file=nuxt.config.ts

Describe the bug

I'm having some trouble when I want to deploy my nuxt project to a github page.
I have added the .nojekyll file under the public folder, but after running generate, files with "_" still appear under public/static.
image
The two files _plugin-vue_export-helper.x3n3nnut.js and name.LPWOZD9u.js will still be generated, causing the website to not run properly after I deploy it to github pages.
image

Additional context

No response

Logs

No response

Copy link

stackblitz bot commented Feb 5, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@mesoul2024
Copy link
Author

I solved this problem.
I found that nuxt3 is built using vite.
I add the following code to nuxt.config.ts

const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
const DRIVE_LETTER_REGEX = /^[a-z]:/i;

export default defineNuxtConfig({

  vite: {
    build: {
      rollupOptions: {
        output: {
          // https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts
          sanitizeFileName(name) {
            const match = DRIVE_LETTER_REGEX.exec(name);
            const driveLetter = match ? match[0] : "";
            return (
              driveLetter +
              name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, "")
            );
          },
        },
      },
    },
  },
...
})

After running npm run generate again, files or folders with "_" will no longer appear under the public folder, and they can be correctly deployed to github pages.

@cdeclerck
Copy link

This solution doesn't work for me. I've also tried adding a step to my github action to touch a .nojekyll file in the .output/public directory but it doesn't change anything. Still no idea?

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

No branches or pull requests

2 participants