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

相关内容

热门资讯

推荐几款新版!德州私人局怎么透... 推荐几款新版!德州私人局怎么透视,pokemmo手机辅助软件,系统教程(有挂透明)是一款可以让一直输...
必备教程!xpoker透视辅助... 必备教程!xpoker透视辅助,HH平台挂,攻略教程(有挂攻略);1分钟了解详细教程(微信 1367...
最新技巧!哈糖大菠萝有挂吗,w... 最新技巧!哈糖大菠萝有挂吗,wepoker私局辅助,可靠技巧(有挂软件);实战中需综合运用上述技巧,...
玩家必看教程!hhpoker怎... 玩家必看教程!hhpoker怎么防作弊,wepoker国外版透视,透明挂教程(有挂方法)是一款可以让...
玩家必看分享!wepoker透... 玩家必看分享!wepoker透视挂底牌,hhpoker可以控制牌吗,德州论坛(有挂技巧)1、不需要A...
今日公布!德州局透视脚本免费版... 今日公布!德州局透视脚本免费版下载手机版,wepoker私人局怎么玩,攻略教程(有挂技巧);玩家必备...
终于懂了!wepoker辅助器... 终于懂了!wepoker辅助器有哪些功能,哈糖大菠萝软件下载,解说技巧(有挂方法);实战中需综合运用...
科普攻略!hhpoker有作弊... 科普攻略!hhpoker有作弊的吗,拱趴大菠萝万能辅助器,曝光教程(有挂透视);建议优先通过拱趴大菠...
专业讨论!aapoker透视脚... 专业讨论!aapoker透视脚本下载,wepoker透视有吗,详细教程(有挂透明)是一款可以让一直输...
记者揭秘!佛手大菠萝辅助,we... 记者揭秘!佛手大菠萝辅助,wepoker辅助软件视频,德州论坛(有挂辅助);实战中需综合运用上述技巧...