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

相关内容

热门资讯

最新消息!斗棋bug,其实是真... 最新消息!斗棋bug,其实是真的辅助挂(有挂方针)-哔哩哔哩1、首先打开斗棋bug辅助器下载最新版本...
事发当天!多乐跑的快脚本,真是... 事发当天!多乐跑的快脚本,真是真的有辅助脚本(有挂助手)-哔哩哔哩多乐跑的快脚本脚本下载中分为三种模...
有了最新消息!多乐够级辅助,一... 有了最新消息!多乐够级辅助,一直是有辅助脚本(有挂解惑)-哔哩哔哩1、点击下载安装,多乐够级辅助脚本...
刚刚!拱趴大菠萝辅助公户,都是... 刚刚!拱趴大菠萝辅助公户,都是是真的辅助脚本(有挂教学)-哔哩哔哩1、玩家可以在拱趴大菠萝辅助公户线...
此事迅速冲上热搜!情怀游戏作z... 此事迅速冲上热搜!情怀游戏作z弊,确实是真的辅助插件(真实有挂)-哔哩哔哩1、在情怀游戏作z弊插件功...
值得注意的是!小闲川南辅助,本... 值得注意的是!小闲川南辅助,本来存在有辅助挂(有挂工具)-哔哩哔哩暗藏猫腻,小编详细说明小闲川南辅助...
做出回应!微信呢小程序微乐房间... 做出回应!微信呢小程序微乐房间怎么开挂,真是是有辅助软件(真的有挂)-哔哩哔哩1.微信呢小程序微乐房...
网友热议!上品游戏破解,确实是... 网友热议!上品游戏破解,确实是有辅助修改器(有挂方针)-哔哩哔哩1、玩家可以在上品游戏破解线上大神俱...
此事引发网友热议!卡五星辅助器... 此事引发网友热议!卡五星辅助器,切实有挂辅助软件(有挂方略)-哔哩哔哩1、卡五星辅助器公共底牌简单,...
昨日!新蜜瓜大厅破解,好像是真... 昨日!新蜜瓜大厅破解,好像是真的辅助神器(有挂教学)-哔哩哔哩所有人都在同一条线上,像星星一样排成一...