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来预渲染时规范化了文件路径长度。

相关内容

热门资讯

6分钟了解!正欢乐达人软件透明... 6分钟了解!正欢乐达人软件透明挂辅助-正欢乐达人其实真的有挂(2024已更新),您好,这款游戏可以开...
线上(红龙扑克作假)竟然是真的... 1、线上(红龙扑克作假)竟然是真的有挂!其实真的有挂(2022已更新)(哔哩哔哩)。2、红龙扑克作假...
五外挂(智星德州安卓版)外挂辅... WePoker透视辅助工具核心要点解析‌,五外挂(智星德州安卓版)外挂辅助插件(软件透明挂)透视辅助...
5分钟科普!全民麻将外挂透视辅... 5分钟科普!全民麻将外挂透视辅助-全民麻将原来真的有挂(2021已更新)是一款可以让一直输的玩家,快...
智能(德扑之星记分牌)其实真的... 智能(德扑之星记分牌)其实真的有挂!其实真的有挂(2020已更新)(哔哩哔哩);是一款可以让一直输的...
8脚本(AAPoker)外挂透... 这是一款非常优秀的AAPoker ia辅助检测软件,能够让你了解到AAPoker中牌率当中全部隐藏参...
5规律(impoker德州)外... 5规律(impoker德州)外挂透明挂辅助器安装(透视)透视辅助(2021已更新)(哔哩哔哩)1、不...
7分钟科普!乐游桌牌外挂透明挂... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加微【439369440】很多玩家在这款游戏中打牌都...
外挂(wpk线上德州俱乐部)原... 1、外挂(wpk线上德州俱乐部)原来是真的有挂!其实真的有挂(2020已更新)(哔哩哔哩)。2、wp...
第十最新版(wepoke存在)... 第十最新版(wepoke存在)软件透明挂辅助机制(辅助挂)透视辅助(2023已更新)(哔哩哔哩);揭...