vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.85k stars 26.86k forks source link

<Link href="/link" /> forwards to "/link.txt" #48996

Closed hariria closed 1 year ago

hariria commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.14.2
      npm: 9.2.0
      Yarn: 1.22.19
      pnpm: 7.25.1
    Relevant packages:
      next: 13.3.0
      eslint-config-next: N/A
      react: N/A
      react-dom: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue

N/A

To Reproduce

next.config.js

/** @type {import('next').NextConfig} */

const withNextra = require('nextra')({
  theme: 'nextra-theme-docs',
  themeConfig: './theme.config.jsx',
})

let withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
})

const nextConfig = {
  reactStrictMode: true,
  experimental: {
    appDir: true,
  },
  images: {
    unoptimized: true,
  },
  output: 'export',
}

if (process.env.NODE_ENV === 'production') {
  module.exports = withNextra(nextConfig)
} else if (process.env.NODE_ENV === 'development') {
  module.exports = withBundleAnalyzer(withNextra(nextConfig))
}
  1. Create a Nextra project with Next.js (currently using Nextra@2.4.2)
  2. Run yarn build to compile as a static site (via output: 'export' in next.config.js)
  3. Serve site via npx serve@latest out

Describe the Bug

import Link from 'next/link';

The <Link href="/docs" /> components I'm using redirect to "/docs.txt", not "/docs" for some reason. It only happens on static export as well (it's fine when I modify my next.config.js to be a non-static export).

Similar to this: https://github.com/vercel/next.js/issues/48414 except I'm using Nextra@2.4.2 and they're using github pages.

Expected Behavior

Expect it to go to "/docs"

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

npx serve@latest out

MangoQuiz commented 1 year ago

I'm having trouble with this stuff too.

Discussion: https://github.com/vercel/next.js/discussions/49098

Question in StackOverFlow: https://stackoverflow.com/questions/76157727/next-js-13-3-appends-txt-to-urls-when-navigating-pages

I also did output: "export" like you do.

I'm waiting the soluition ;(

dhruvilxcode commented 1 year ago

it doesn't work either for export: standalone

If anyone can suggest or provide fix would be good!

dhruvilxcode commented 1 year ago

ok i found the fix, i downgraded next version to 13.2

npm i next@13.2

and it worked well for me.

MangoQuiz commented 1 year ago

ok i found the fix, i downgraded next version to 13.2

npm i next@13.2

and it worked well for me.

Oh GOD! I fixed it too. I downgraded it version to "13.2.0"

Thanks.

timneutkens commented 1 year ago

@hariria Nexta doesn't support App Router / output: 'export' yet.

@MangoQuiz the reason it breaks for you is because you're using output: 'export' incorrectly. You can't use next start when using output: 'export'. You have to use a static file server instead. If you're using next start it's better to not add output: 'export' to next.config.js. Static pages are already the default.

@dhruvilxcode output: 'standalone' is a different feature, we're working on a fix here: https://github.com/vercel/next.js/pull/49116

MangoQuiz commented 1 year ago

@timneutkens Thank you for replying! I'm kinda newbie in web development.

If you don't mind me asking, how can I use a static file server in details? Remove output: 'export' after build it? or next build and next start without output: 'export'

dhruvilxcode commented 1 year ago

@timneutkens even without standalone export feature, it's not working for that too.

Note: I am using middleware with appDir enabled.

timneutkens commented 1 year ago

Please open a new issue with a complete reproduction 🙏

dhruvilxcode commented 1 year ago

49130

thangcmo commented 1 year ago

ok i found the fix, i downgraded next version to 13.2

npm i next@13.2

and it worked well for me.

I fixed it too. I downgraded it version to "13.2.3"

leonahliang90 commented 1 year ago

even have downgraded to version 13.2.3, it might work for this Link href, but anything below 13.3 version would not have export feature ready if your appDir is true.

experimental: {
    appDir: true,
  },

either wait for official fix or change from App Router to Page Router

y0zong commented 1 year ago

@timneutkens

@hariria Nexta doesn't support App Router / output: 'export' yet.

I have same problem here when I try to deploy SPA project(output: 'export') to Nginx, does Nextjs team have any plan to support it?

Afellman commented 1 year ago

I have this issue using router.push with output: "export". When I try to navigate to home with router.push("/") it tries to fetch a .txt file...

batazor commented 1 year ago

I confirm, this is a very strange behavior, I see that in the code for some reason make the concatenation of the path with .txt maybe we can remove it?

deyvisonborges commented 1 year ago

This script solves your problem. Replace the start command with:

package.json

{
  "start": "npx serve ./build/"
}
batazor commented 1 year ago

@deyvisonborges I use export and my docker image has only nginx, I can't run npx, node, etc

dscafati commented 1 year ago

This is fixed at least on 13.4.7, could you all please check that?

htakemoto commented 1 year ago

I confirmed that the version 13.4.7 fixed the link issue with output: 'export' in next.config.js, however, if the url path is longer than 56 chars, the link is cut in the middle.

timneutkens commented 1 year ago

This issue was indeed fixed in this PR: https://github.com/vercel/next.js/pull/50974/files#diff-7b6239af735eba0c401e1a0db1a04dd4575c19a031934f02d128cf3ac813757bR73-R81

@htakemoto happy to take a look at what you're running into, but can't reproduce it. Can you open a new issue that explains how to reproduce it? Thanks!

github-actions[bot] commented 1 year ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.