node.js - writeFileSync 上的 ENOENT 在 repl 上工作在 gulp-asset-manifest 上失败

标签 node.js gulp

我正在使用 this site 上的代码为 Windows aspnet + angularjs 应用程序编写 gulp 文件。

我现在只运行样式,当我运行 gulp 时,我得到:

Error: ENOENT, no such file or directory 'C:\project\build\manifest-debug.json'
at Error (native)
at Object.fs.openSync (fs.js:502:18)
at Object.fs.writeFileSync (fs.js:1103:15)
at writeManifestFile (C:\project\node_modules\gulp-asset-manifest\index.js:30:8)
at resetManifestFile (C:\project\node_modules\gulp-asset-manifest\index.js:51:5)
at module.exports (C:\project\node_modules\gulp-asset-manifest\index.js:76:5)
at getManifest (C:\project\Gulpfile.js:97:12)
at Gulp.<anonymous> (C:\project\Gulpfile.js:126:15)
at module.exports (C:\project\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\project\node_modules\gulp\node_modules\orchestrator\index.js:273:3)

查看C:\project\node_modules\gulp-asset-manifest\index.js:30:8我明白了:

fs.writeFileSync(filename, JSON.stringify(data));

所以我在 Node 的 REPL 上运行了这个:

fs.writeFileSync('C:\\project\\build\\manifest-debug.json', 'hi');

文件已正确创建。

我尝试使用现有文件再次运行 gulp 并得到完全相同的错误。

我在index.js的第30行之前添加了一个console.log(filename);,我得到了:

./build/manifest-debug.json

所以我在同一个文件夹的 REPL 上运行了 fs.writeFileSync('./build/manifest-debug.json', 'hi'); 并且它也有效。

不知道发生了什么。

我在禁用 UAC 的情况下运行所有​​内容,并在具有管理员权限的命令提示符下运行。

最佳答案

问题是 fs.writeFileSync 需要路径存在。

在调用 gulp-asset-manifest 时,./build 不存在,因为 clean 任务删除了整个路径。

关于node.js - writeFileSync 上的 ENOENT 在 repl 上工作在 gulp-asset-manifest 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29848807/

相关文章:

json - package.json 中的相对路径?

javascript - Node.js 中的 SetTimeout 问题

node.js - serverless-s3-local 插件和 @aws-sdk/client-s3 使用 PutObjectCommand 返回错误

node.js - 我是否需要使用 .quit() 退出我的 Node redis 客户端实例?

javascript - 存储具有到期日期的 session 数据

javascript - 如何在 gulp.src.options.base 中动态解析路径

javascript - 如何解决 "module is not defined"错误?

javascript - Browserify 需要目录中的所有文件

javascript - “gulp-babel”在 Node js 版本 4 中不起作用

angularjs - 在 mean.js 项目中运行 npm test 时出错