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

相关内容

热门资讯

新版有挂开挂!微信大厅辅助挂,... 您好:微信大厅辅助挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特...
今日头条辅助!天天微友有辅助么... 今日头条辅助!天天微友有辅助么,poker master辅助(揭秘一下开挂辅助脚本);无需打开直接搜...
有挂透视开挂!山西扣点辅助工具... 有挂透视开挂!山西扣点辅助工具,wepoker辅助是真的吗(交流学习经验开挂辅助工具);亲,山西扣点...
有挂细节辅助!微信小程序微乐辅... 您好:微信小程序微乐辅助器脚本这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
有挂助手开挂!广西友乐辅助ap... 广西友乐辅助app开挂教程视频分享装挂详细步骤在当今的网络游戏中,广西友乐辅助app作为一种经典的娱...
发现有挂开挂!宝宝游戏辅助器,... 发现有挂开挂!宝宝游戏辅助器,福建天天开心辅助工具(一分钟揭秘开挂辅助安装)【无需打开直接搜索加薇1...
真实有挂辅助!情怀至友开挂,w... 您好:情怀至友开挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
讲解有挂辅助!乐平包王攻略,传... 讲解有挂辅助!乐平包王攻略,传送屋激k有挂吗(每日必备开挂辅助神器)【无需打开直接搜索加薇13670...
有挂方法开挂!圣盛鄂州晃晃辅助... 有挂方法开挂!圣盛鄂州晃晃辅助,随意玩挂(透视透视挂开挂辅助工具) >>您好:软件加薇1367043...
有挂规律开挂!朋朋政和辅助,拱... 有挂规律开挂!朋朋政和辅助,拱趴大菠萝挂(玩家科普开挂辅助插件);无需打开直接搜索打开薇:13670...