简体   繁体   English

对目录的非法操作,copyFile './source/package.json' -> '/']

[英]illegal operation on a directory, copyFile './source/package.json' -> '/']

I am trying to copy file from source to destination getting this error我正在尝试将文件从源复制到目标,但出现此错误

[EISDIR: illegal operation on a directory, copyFile './source/package.json' -> './'] {
  code: 'EISDIR',
  errno: -21,
  path: './source/package.json',
  syscall: 'copyFile',
  dest: './'
}

don't know where I am doing wrong.不知道我哪里做错了。

// run `node index.js` in the terminal

const fs = require('fs');

// File destination.txt will be created or overwritten by default.
fs.copyFile('./source/package.json', './', (err) => {
  if (err) throw err;
  console.log('source.txt was copied to destination.txt');
});

here is my code https://stackblitz.com/edit/node-rwj4vr?file=source%2Fpackage.json,index.js这是我的代码https://stackblitz.com/edit/node-rwj4vr?file=source%2Fpackage.json,index.js

second concern is can we pass name attribute to replace this第二个问题是我们可以通过name属性来替换它吗

{
  "name":"$name"
}

why this is not working为什么这不起作用

fs.copyFile('./source/package.json', './dest/package.json', (err) => {
  if (err) throw err;
  console.log('source.txt was copied to destination.txt');
});

expected it should create dest folder and put file there预计它应该创建dest文件夹并将文件放在那里

Your problem is that you try to copy the file as a directory ( copyFile ref ) instead of a file, to fix it change the code to:您的问题是您尝试将文件复制为目录( copyFile ref )而不是文件,要修复它,请将代码更改为:

fs.copyFile('./source/package.json', './package.json', (err) => {
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM