// next.js defines / to be an invalid basepath, whereas in cocalc it is valid:1const BASE_PATH = process.env.BASE_PATH ?? "/";23// next.js definition:4const basePath = BASE_PATH == "/" ? "" : BASE_PATH;56const { join, resolve } = require("path");78// Important! We include resolve('.') and basePath to avoid9// any possibility of multiple cocalc installs or different base10// paths conflicting with each other and causing corruption.11const cacheDirectory = join(12`/tmp/nextjs-${require("os").userInfo().username}`,13basePath,14resolve("."),15);1617const config = {18basePath,19env: { BASE_PATH },20eslint: { ignoreDuringBuilds: true },21webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {22// Webpack breaks without this pg-native alias, even though it's dead code,23// due to how the pg module does package detection internally.24config.resolve.alias["pg-native"] = ".";25// These aliases are so we don't end up with two distinct copies26// of React in our application, since this doesn't work at all!27config.resolve.alias["react"] = resolve(__dirname, "node_modules", "react");28config.resolve.alias["react-dom"] = resolve(29__dirname,30"node_modules",31"react-dom",32);33// Important: return the modified config34return config;35},36// For i18n, see https://nextjs.org/docs/advanced-features/i18n-routing37// We are doing this at all since it improves our Lighthouse accessibility score.38i18n: {39locales: ["en-US"],40defaultLocale: "en-US",41},42poweredByHeader: false,43};4445const withRspack = require("next-rspack");46// use NO_RSPACK to build without RSPACK. This is useful on a machine with a lot47// of RAM (and patience) since it supports hot module reloading (so you don't have48// to refresh after making changes).4950if (process.env.NO_RSPACK) {51module.exports = config;52} else {53module.exports = withRspack(config);54}555657