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

相关内容

热门资讯

教程攻略!pokerworld... 教程攻略!pokerworld软件(辅助挂)总是是真的有挂(确实有挂辅助插件)1、让任何用户在无需安...
安装程序教程!wpk透视插件(... 安装程序教程!wpk透视插件(辅助挂)竟然真的有挂(有挂方略辅助软件)1、玩家可以在线上大神俱乐部对...
推荐一款!wpk透视辅助靠谱吗... 推荐一款!wpk透视辅助靠谱吗(辅助挂)真是是有挂(有挂攻略辅助脚本)1、下载好透视辅助下载之后点击...
玩家科普!德普之星透视辅助插件... 玩家科普!德普之星透视辅助插件(辅助挂)好像有挂(的确有挂辅助app)该软件可以轻松地帮助玩家将外卦...
传递经验!wepokerplu... 传递经验!wepokerplus外挂(辅助挂)好像是真的有挂(有挂方略辅助app)1、打开软件启动之...
玩家爆料!hhpoker德州有... 玩家爆料!hhpoker德州有挂吗(辅助挂)一直真的有挂(有挂工具辅助教程)一、游戏安装教程牌型概率...
重大通报!fishpoker透... 重大通报!fishpoker透视底牌(辅助挂)切实是有挂(存在有挂辅助软件)1、用户打开应用后不用登...
一分钟揭秘!wepoker养号... 一分钟揭秘!wepoker养号规律(辅助挂)原来是真的有挂(有挂实锤辅助app)1、该软件可以轻松地...
最新技巧!newpoker怎么... 最新技巧!newpoker怎么安装脚本(辅助挂)好像真的有挂(有挂教学辅助方法)1、玩家可以在线上大...
我来教教你!wepoker辅助... 我来教教你!wepoker辅助器是真的吗(辅助挂)一贯是有挂(真实有挂辅助技巧)我来教教你!wepo...