javascript - Node.js 连接反斜杠问题

标签 javascript node.js concatenation

所以我目前正在为 Angular 项目进行微前端设置。当尝试创建一组要在不同项目之间共享的 polyfill、es5 脚本等时,由于某种原因,正在创建的目录包含反斜杠,导致找不到路径。如果这些是正斜杠,它们会很好地工作,想法吗?

const fs = require('fs-extra');
const concat = require('concat');

(async function build(){
const prgName = process.argv.slice(2)[0];
if(prgName === '' || prgName === undefined){
console.log("Project name is required as an argument");
}else{
const files_es2015 = [
    './dist/' + prgName + '/polyfill-webcomp-es5.js',
    './dist/' + prgName + '/polyfill-webcomp.js',
    './dist/' + prgName + '/polyfill-es2015.js',
    './dist/' + prgName + '/scripts.js',
    './dist/' + prgName + '/main-es2015.js',
]
await fs.ensureDir('./dist/' + prgName + '/elements');
await concat(files_es2015,'./dist/' + prgName + '/elements/' + prgName + '-elements-es2015.js');

const files_es5 = [
    './dist/' + prgName + '/polyfill-webcomp-es5.js',
    './dist/' + prgName + '/polyfill-webcomp.js',
    './dist/' + prgName + '/polyfill-es2015.js',
    './dist/' + prgName + '/scripts.js',
    './dist/' + prgName + '/main-es5.js',
]
await fs.ensureDir('./dist/' + prgName + '/elements');
await concat(files_es2015,'./dist/' + prgName + '/elements/' + prgName + '-elements-es5.js');

console.log('Done generating bundles for ' + prgName);
}
})()

尝试创建构建时将输出以下消息

    (node:26344) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'C:\Code\Project\Code Testing\project-UI-Workspace\dist\classroomApp\polyfill-es2015.js'
(Use `node --trace-warnings ...` to show where the warning was created)
(node:26344) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:26344) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

文件夹设置,从project-UI-workspace文件夹查看。这是运行脚本之后的结果,因此您可以看到 elements 文件夹被创建,但由于路径错误,没有任何内容进入。

enter image description here

最佳答案

  • 当我尝试将多个 javascript 文件合并到一个文件中时,我遇到了同样的问题。通过用双反斜杠替换单反斜杠修复了这个问题。

例如:如果路径是:C:\Users\samplecode.js 将其更改为 C:\\Users\\samplecode.js

关于javascript - Node.js 连接反斜杠问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66649488/

相关文章:

javascript - Knockout.js 单击更改(不切换)css 类

javascript - 使用 jQuery 更改 SVG 元素的 "xlink:href"属性

javascript - EXTJS 4.1 如何选择树面板中的下一个叶节点

node.js - 如何进行 Twitter OAuth Echo 验证调用?

node.js - 使用 pm2 部署多个 Angular 4 项目

javascript - Node.js 服务器上的实时视频流

android - SQLite 将列转换为逗号分隔的字符串

javascript - 在服务器上创建一个复选框,使用 javascript 处理函数

mysql - 如何在 MySQL 中的现有字符串末尾插入字符串类型的数据字段,有点像 CONCAT

python - 像在 MATLAB 中一样在 Python 中连接矩阵/向量?