cpSync with recurse:true results in ENOENT
Aderinom opened this issue · 0 comments
Aderinom commented
What version of pkg are you using?
5.8.1
What version of Node.js are you using?
18.18.2
What operating system are you using?
debian11 (bullseye)
What CPU architecture are you using?
x86_64
What Node versions, OSs and CPU architectures are you building for?
node18-linux-x64
Describe the Bug
I'm trying to copy files out of the packaged binary into a temp path using:
cpSync(resolve(__dirname, 'files'), '/tmp/testout', { recursive: true });
This results in
node:internal/fs/utils:347
throw err;
^
Error: ENOENT: no such file or directory, opendir '/snapshot/app/build/files'
at opendirSync (node:internal/fs/dir:276:3)
at copyDir (node:internal/fs/cp/cp-sync:278:15)
at mkDirAndCopy (node:internal/fs/cp/cp-sync:273:3)
at onDir (node:internal/fs/cp/cp-sync:267:25)
at getStats (node:internal/fs/cp/cp-sync:171:12)
at handleFilterAndCopy (node:internal/fs/cp/cp-sync:158:10)
at cpSyncFn (node:internal/fs/cp/cp-sync:60:10)
at cpSync (node:fs:2904:3)
at Object.<anonymous> (/snapshot/app/build/main.js)
at Module._compile (pkg/prelude/bootstrap.js:1926:22) {
errno: -2,
syscall: 'opendir',
code: 'ENOENT',
path: '/snapshot/app/build/files'
}
The files however are included, I'm checking this by reading the directory with readdirSync.
Copying the files one by one with the full path using cpSync works.
Expected Behavior
Expecting cpSync with recurse to correctly copy the folder to the target direcroy.
To Reproduce
Assuming following project structure:
files
- test.sql
main.js
with pkg config:
"pkg": {
"assets": [
"**/*.sql",
],
"targets": [
"node18-linux-x64"
],
"outputPath": "_bin_release"
},
and code:
const dir = resolve(__dirname, 'files');
console.log('Dir is : ' + dir);
const files = readdirSync(dir);
for (const file of files) {
console.log('Dir has: ' + file);
}
console.log('CpSync fails with:');
cpSync(resolve(__dirname, 'files'), '/tmp/testout', { recursive: true });
Will correctly log the existing files, however fail when trying to do cpSync:
Dir is : /snapshot/app/build/files
Dir has: test.sql
CpSync fails with:
node:internal/fs/utils:347
throw err;
^
Error: ENOENT: no such file or directory, opendir '/snapshot/app/build/files'
at opendirSync (node:internal/fs/dir:276:3)
at copyDir (node:internal/fs/cp/cp-sync:278:15)
at mkDirAndCopy (node:internal/fs/cp/cp-sync:273:3)
at onDir (node:internal/fs/cp/cp-sync:267:25)
at getStats (node:internal/fs/cp/cp-sync:171:12)
at handleFilterAndCopy (node:internal/fs/cp/cp-sync:158:10)
at cpSyncFn (node:internal/fs/cp/cp-sync:60:10)
at cpSync (node:fs:2904:3)
at Object.<anonymous> (/snapshot/app/build/main.js)
at Module._compile (pkg/prelude/bootstrap.js:1926:22) {
errno: -2,
syscall: 'opendir',
code: 'ENOENT',
path: '/snapshot/app/build/files'
}