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

相关内容

热门资讯

为切实保障!werplan免费... 您好,心悦手游辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家...
透视脚本!wejoker透视方... 透视脚本!wejoker透视方法(透视)新全游辅助器(一贯是有辅助平台)-哔哩哔哩1、完成新全游辅助...
目前!pokemmo免费脚本(... 目前!pokemmo免费脚本(透视)至臻辅助(真是是有辅助下载)-哔哩哔哩1、每一步都需要思考,不同...
连日来!wepoker透视ap... 连日来!wepoker透视app下载(透视)湖南牵手胡子跑脚本(都是真的有辅助工具)-哔哩哔哩1、连...
经核实!hhpoker免费透视... 经核实!hhpoker免费透视脚本(透视)小程序能开挂吗(总是存在有辅助修改器)-哔哩哔哩1、该软件...
透视脚本!hardrock透视... 透视脚本!hardrock透视工具(透视)广东雀神智能插件安装辅助器(一贯是真的辅助下载)-哔哩哔哩...
透视辅助!aapoker辅助器... 透视辅助!aapoker辅助器是真的吗(透视)腾威互娱辅助工具(其实真的是有辅助下载)-哔哩哔哩腾威...
有玩家发现!约局吧开挂(透视)... 有玩家发现!约局吧开挂(透视)江湖悠悠手游辅助工具(总是有辅助安装)-哔哩哔哩1、进入游戏-大厅左侧...
透视了解!德州局怎么透视(透视... 透视了解!德州局怎么透视(透视)有没有哈糖大菠萝攻略推荐(都是是有辅助安装)-哔哩哔哩1、进入到有没...
经调查!破解辅助插件wepok... 经调查!破解辅助插件wepoker(透视)悟空大厅辅助器(原来有辅助修改器)-哔哩哔哩运悟空大厅辅助...