微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Next 编译成功后出现 JS Build 错误

如何解决Next 编译成功后出现 JS Build 错误

我在 next.config.js 中为 NextJS 创建了一个 webpack 配置。编译后出现一些关于导出路径的构建错误。任何人都请帮我解决这个问题。 这是我的 next.config.js 如果需要任何更改有助于避免错误

module.exports = {
    rewrites: async () => nextI18NextRewrites(localeSubpaths),publicRuntimeConfig: {
       localeSubpaths,},compress: true,webpack: (config,option) => {
        config.optimization = {
            splitChunks: {
            chunks: 'all',cacheGroups: {
                default: false,vendors: false,framework: {
                    name: 'framework',chunks: 'all',test: /[\\/]node_modules[\\/](react|react-dom|scheduler|prop-types)[\\/]/,priority: 20,minChunks: 5,reuseExistingChunk: true,lib: {
                   chunks: 'all',test: (module) => {
                       return (
                           module.size() > 160000 && /node_modules[/\\]/.test(module.identifier()))
                    },name: (module) => {
                        const rawRequest = module.rawRequest && module.rawRequest.replace(/^@(\w+)[/\\]/,'$1-') if (rawRequest) return rawRequest
                        const identifier = module.identifier()
                        const trimmedIdentifier = /(?:^|[/\\])node_modules[/\\](.*)/.exec(identifier)
                        const processedIdentifier = rimmedIdentifier && trimmedIdentifier[1].replace(/^@(\w+)[/\\]/,'$1-')    
                        return processedIdentifier || identifier
                    },priority: 30,minChunks: 2,commons: {
      name: 'commons',minChunks: 25,priority: 10,shared: {
      name(module,chunks) {
        return require("crypto")
          .createHash('sha1')
          .update(
            chunks.reduce(
              (acc,chunk) => {
                return acc + chunk.name
              },''
            )
          )
          .digest('base64')
          .replace(/\//g,'')
      },priority: 5,maxInitialRequests: 20,}
}
return config;
}
}

这是我在 next build 之后得到的错误 错误

> Build error occurred
Error: Cannot find module for page: /404
at pageNotFoundError (/Users/vigraman/Projects/ulp-web/node_modules/next/dist/next- 
server/server/require.js:1:384)
at getPagePath (/Users/vigraman/Projects/ulp-web/node_modules/next/dist/next- 
server/server/require.js:1:917)
at /Users/vigraman/Projects/ulp-web/node_modules/next/dist/build/index.js:15:3168
at runMicrotasks (<anonymous>)
at processticksAndRejections (internal/process/task_queues.js:97:5)
at async Promise.all (index 0)
at async build (/Users/vigraman/Projects/ulp- 
web/node_modules/next/dist/build/index.js:15:2729) {
code: 'ENOENT'
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。