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 export with exportPathMap in next.config.js creates a duplicate 404.html.html #36855

Closed
1 task done
mdubourg001 opened this issue May 12, 2022 · 4 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@mdubourg001
Copy link

mdubourg001 commented May 12, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

$ yarn next info

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.1.0
      npm: 8.8.0
      Yarn: 3.2.0
      pnpm: N/A
    Relevant packages:
      next: 12.1.6
      react: 18.1.0
      react-dom: 18.1.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

This is actually a following of #33464.

Running yarn build && yarn export while using an updated exportPathMap in next.config.js leads to the creation of an extra 404.html.html file in export. It only happens if the object returned from exportPathMap doesn't have a key named /404.

For example, my goal was to create each page in an index.html in a directory with the same name (ie. /about.html becomes /about/index.html):

When using this next.config.js, the export produces an extra 404.html.html file (ie. the bug happens)...

// next.config.js

module.exports = {
  exportPathMap: async function (defaultPathMap) {
    const pathMap = {};

    for (const [path, config] of Object.entries(defaultPathMap)) {
      if (path === "/") {
        pathMap[path] = config;
      } else {
        pathMap[`${path}/index`] = config;
      }
    }

    return pathMap;
  }
}

... while when using this one, it doesn't happen:

// next.config.js

module.exports = {
  exportPathMap: async function (defaultPathMap) {
    // 🚩the only difference is here, we spread the default pathMap
    const pathMap = { ...defaultPathMap };

    for (const [path, config] of Object.entries(defaultPathMap)) {
      if (path === "/") {
        pathMap[path] = config;
      } else {
        pathMap[`${path}/index`] = config;
      }
    }

    return pathMap;
  }
}

Expected Behavior

The 404.html.html page should not be created when using a custom exportPathMap in next.config.js.

To Reproduce

  1. Open https://stackblitz.com/edit/nextjs-rxdeeq
  2. Run npx next build && npx next export in the terminal
  3. 404.html.html has been created in the out/ directory
@mdubourg001 mdubourg001 added the bug Issue was opened via the bug report template. label May 12, 2022
@mdubourg001 mdubourg001 changed the title next export with exportPathMap in next.config.js creates duplicates 404.html and 404.html.html next export with exportPathMap in next.config.js creates a duplicate 404.html.html May 12, 2022
@hanneslund
Copy link
Contributor

I think #36827 fixed this already.

@mdubourg001
Copy link
Author

@hanneslund I don't think this PR fixes the same issue. I understand why the export of /404.html is enforced, but I'm not sure the export of /404.html.html should be:

exportPathMap['/404'] = exportPathMap['/404.html'] = {

mdubourg001 pushed a commit to mdubourg001/next.js that referenced this issue May 12, 2022
SukkaW added a commit to SukkaW/next.js that referenced this issue May 14, 2022
SukkaW added a commit to SukkaW/next.js that referenced this issue May 14, 2022
kodiakhq bot pushed a commit that referenced this issue May 14, 2022
## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

The PR fixes #30300 and #36855.

The corresponding integration test case has been added.
@SukkaW
Copy link
Contributor

SukkaW commented May 14, 2022

@mdubourg001

The issue should be solved by #36827 already. I have forked your stackblitz reproduction, and updated Next.js to the next@canary, and no 404.html.html is being exported: https://stackblitz.com/edit/nextjs-oujzwx

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants