Deployement of a Docusaurus v2 within a monorepo : Page Not Found

Hello,

I would like to set up an preview site for my repo https://github.com/jy95/docusaurus-json-schema-plugin for pull requests.
So I took my Github actions “documentation” as an starting base but got this :

Page Not Found. Looks like you’ve followed a broken link or entered a URL that doesn’t exist on this site.

Downloading my assets throws me a “Error during download”

What can you suggest me to fix that situation ?
For info, reproducible branch is https://github.com/jy95/docusaurus-json-schema-plugin/pull/57

Here are my config files :

# netlify.toml

[build.environment]
  NODE_VERSION = "18"

[context.deploy-preview]
  command = "npm install netlify-cli@13.2.2 -g && npm install && npm run build && npm link && cd testsite && npm link docusaurus-json-schema-plugin --save && npm install --prefer-dedupe && npm run build && netlify deploy --prod --dir build --auth $NETLIFY_AUTH_TOKEN"
  environment = { NETLIFY_SITE_ID = "b99768d3-7f47-4cc9-9ff1-ad23a359dadc" }

docusaurus.config.js :

const path = require("path")

const isDeployPreview = !!process.env.NETLIFY
const baseUrl = isDeployPreview ? "/" : "/docusaurus-json-schema-plugin/"

// With JSDoc @type annotations, IDEs can provide config autocompletion
/** @type {import('@docusaurus/types').DocusaurusConfig} */
module.exports = {
  title: "Docusaurus JSON Schema Plugin",
  tagline: "JSON Schema plugin viewer / editor in Docusaurus",
  url: "https://jy95.github.io",
  baseUrl: baseUrl,
  onBrokenLinks: "throw",
  onBrokenMarkdownLinks: "warn",
  favicon: "img/favicon.ico",
  trailingSlash: false, // Needed for Gh pages - https://github.com/facebook/docusaurus/issues/5026
  organizationName: "jy95", // Usually your GitHub org/user name.
  projectName: "docusaurus-json-schema-plugin", // Usually your repo name.
  themeConfig: {
    navbar: {
      title: "JSON Schema viewer / editor",
      logo: {
        alt: "My Site Logo",
        src: "img/project_icon.svg",
      },
      items: [
        {
          to: "docs/demo/",
          activeBasePath: "docs",
          label: "Demos",
          position: "left",
        },
        {
          to: "playground",
          label: "Playground",
          position: "left",
        },
        {
          label: "Github",
          position: "right",
          to: "https://github.com/jy95/docusaurus-json-schema-plugin",
        },
      ],
    },
    footer: {
      style: "dark",
      links: [],
      copyright: `Copyright © ${new Date().getFullYear()}. Built with Docusaurus.`,
    },
  },
  presets: [
    [
      "@docusaurus/preset-classic",
      {
        docs: {
          // https://docusaurus.io/docs/markdown-features/code-blocks#npm2yarn-remark-plugin
          remarkPlugins: [
            [require("@docusaurus/remark-plugin-npm2yarn"), { sync: true }],
          ],
          sidebarPath: require.resolve("./sidebars.js"),
          // Please change this to your repo.
          editUrl:
            "https://github.com/jy95/docusaurus-json-schema-plugin/tree/main/testsite/",
        },
        // Optional: disable the blog plugin
        blog: false,
        theme: {
          customCss: require.resolve("./src/css/custom.css"),
        },
      },
    ],
  ],
  themes: [["docusaurus-json-schema-plugin", {}]],
  // Ugly trick to deal with "Invalid hook"
  plugins: [
    () => ({
      name: "resolve-react",
      configureWebpack() {
        return {
          resolve: {
            alias: {
              // assuming root node_modules is up
              react: path.resolve("../node_modules/react"),
            },
          },
        }
      },
    }),
  ],
}

Thanks in advance

@jy95 Your build command is written as if it is being executed elsewhere, rather than on Netlify.

My guess is that’s what you mean by “I took my Github actions documentation as a starting base”.

You won’t need to install the netlify-cli, or do a netlify-cli deploy, when you’re executing the build on Netlify.

All you should need to run is the main build itself, to produce the output, and to ensure that the Publish directory is set to the right folder.

1 Like

Can’t I set that to my toml file instead ?

Sure you can @jy95.

However, both the netlify.toml and the build settings in the screenshot are missing the publish directory. So even if the convoluted build command you have specified does work Netlify doesn’t know where the output it is meant to publish is located.

1 Like

… and by default it will assume the root of your repository is the publish directory.

2 Likes

Thanks.
Is there a way to enable it only for preview / pull requests (and not on main branch as I already have the github pages) ?

Netlify will always build the main branch, all other deploys are optional. If you only wish to configure some settings for different context, check out: Introducing Deploy Contexts in Netlify