Angular预渲染对于小于260个字符的文件路径抛出ENAMETOOLONG错误。
创始人
2024-10-30 19:00:13
0

这个错误通常发生在Windows环境中,因为Windows系统对于文件路径长度有限制。解决方案是使用Node.js中的path模块来规范化文件路径并确保长度不超过260个字符。可以在Angular应用的webpack配置文件中使用以下代码来实现:

const path = require('path'); const { AngularCompilerPlugin } = require('@ngtools/webpack');

module.exports = { entry: './src/main.ts', output: { path: path.join(__dirname, 'dist'), filename: 'app.bundle.js' }, resolve: { extensions: ['.ts', '.js'] }, module: { rules: [ { test: /.ts$/, loader: "@ngtools/webpack" }, { test: /.html$/, loader: 'html-loader' } ] }, plugins: [ new AngularCompilerPlugin({ tsConfigPath: './tsconfig.json', entryModule: path.join(__dirname, 'src/app/app.module#AppModule'), skipCodeGeneration: true }), function () { this.plugin('done', stats => { const pr = require('prerender-node'); pr.set('prerenderServiceUrl', 'http://localhost:3000/'); pr.set('prerenderToken', 'MY_PRERENDER_TOKEN'); pr.set('renderAfterDocumentEvent', 'app-ready'); pr.set('chromeLocation', '/usr/bin/chromium-browser'); //your Chrome/Chromium binary path

    const paths = ['/', '/about', '/contact'];
    paths.forEach((path) => {
      const fullPath = path.startsWith('/') ? path.slice(1) : path;
      const url = `http://localhost:4200/${fullPath}`;
      const filePath = `/dist/${path}.html`;
      pr.capturePhantom(url, { output: filePath }, () => {
        console.log(`Prerendered ${url} to ${filePath}`);
      });
    });
  });
}

] };

这个配置文件中使用了path.join方法来确保输出路径的正确性,并在使用prerender-node来预渲染时规范化了文件路径长度。

相关内容

热门资讯

透视规律!aapoker辅助器... 透视规律!aapoker辅助器怎么用(透视)真的假的(一直有挂)1、全新机制【aapoker辅助器怎...
透视辅助!佛手在线有挂吗(透视... 透视辅助!佛手在线有挂吗(透视)详细教程(2025已更新)(哔哩哔哩)1、不需要AI权限,帮助你快速...
透视游戏!aapoker透视脚... 透视游戏!aapoker透视脚本下载(透视)透视脚本下载(其实有挂)1、完成aapoker透视脚本下...
透视新版!pokemmo脚本最... 透视新版!pokemmo脚本最新版(透视)可靠教程(2020已更新)(哔哩哔哩);pokemmo脚本...
透视规律!aapoker透视脚... 透视规律!aapoker透视脚本(透视)万能辅助器(都是有挂)小薇(透视辅助)致您一封信;亲爱aap...
透视挂透视!约局吧如何查看是否... 透视挂透视!约局吧如何查看是否有挂(透视)教你攻略(2021已更新)(哔哩哔哩)1)约局吧如何查看是...
透视实锤!拱趴大菠萝挂哪里(透... 透视实锤!拱趴大菠萝挂哪里(透视)存在挂教程(2023已更新)(哔哩哔哩)1、下载好拱趴大菠萝挂哪里...
透视新版!aapoker辅助器... 透视新版!aapoker辅助器怎么用(透视)插件下载(真是真的是有挂);1、下载好aapoker辅助...
透视app!xpoker辅助(... 透视app!xpoker辅助(透视)教你攻略(2025已更新)(哔哩哔哩)1、实时xpoker辅助开...
透视了解!aapoker辅助器... 透视了解!aapoker辅助器是真的吗(透视)插件下载(真是存在有挂);1、aapoker辅助器是真...