首页 > 解决方案 > Next.js:尽管在 next.config.js 中有一个 exportPathMap,但找不到 exportPathMap

问题描述

错误:

No "exportPathMap" found in "next.config.js". Generating map from "./pages"


但我确实exportPathMap基于官方文档

我的next.config.js包含:

const withCss = require("@zeit/next-css");
const withSass = require("@zeit/next-sass");
const withTM = require("next-transpile-modules");

module.exports = {
  exportPathMap: async function(
    defaultPathMap,
    { dev, dir, outDir, distDir, buildId }
  ) {
    return {
      "/": { page: "/" },
      "/menu": { page: "/menu" },
      "/about": { page: "/about" }
    };
  }
};

module.exports = withCss({
  cssModules: true
});

module.exports = withSass(
  withTM({
    transpileModules: ["react-bulma-components"],
    sassLoaderOptions: {
      includePaths: ["./components"]
    }
  })
);

我还尝试删除默认映射:

module.exports = {
  exportPathMap: async function() {
    return {
      "/": { page: "/" },
      "/menu": { page: "/menu" },
      "/about": { page: "/about" }
    };
  }
};

以及withCss()根据我的研究将其移动到内部:

module.exports = withCss({
  exportPathMap: async function() {
    return {
      "/": { page: "/" },
      "/menu": { page: "/menu" },
      "/about": { page: "/about" }
    };
  }
});

这两个出口似乎正在工作,但我做错了什么withSass()withCss()


编辑:

next.config.js在根项目目录中,如果您有任何疑问的话。

标签: javascriptnext.js

解决方案


您正在重新分配您的 module.exports 多次,因此exportPathMapandwithCss丢失了。在这种情况下,配置应如下所示:

module.exports = withCss(
  withSass(
    withTM({
      transpileModules: ["react-bulma-components"],
      sassLoaderOptions: {
        includePaths: ["./components"]
      },
      exportPathMap: async function(
        defaultPathMap,
        { dev, dir, outDir, distDir, buildId }
      ) {
        return {
          "/": { page: "/" },
          "/menu": { page: "/menu" },
          "/about": { page: "/about" }
        };
      }
    })
  )
);

推荐阅读