question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to copy dotfiles with `.copy`

See original GitHub issue
  • Laravel Mix Version: 6.0.16
  • Node Version: v14.16.0
  • NPM Version: 6.14.11
  • OS: macOS 11.1 Big Sur

Description:

If I try to copy a dotfile:

mix.copy('src/.htaccess', 'build/.htaccess')

I get this error:

(node:54876) UnhandledPromiseRejectionWarning: Error: ENOTDIR: not a directory, scandir '/Users/username/path/to/project/src/.htaccess'
    at Object.readdirSync (fs.js:1021:3)
    at FileCollection.copyTo (/Users/username/path/to/project/node_modules/laravel-mix/src/FileCollection.js:85:30)
    at /Users/username/path/to/project/node_modules/laravel-mix/src/FileCollection.js:77:38
    at Array.forEach (<anonymous>)
    at FileCollection.copyTo (/Users/username/path/to/project/node_modules/laravel-mix/src/FileCollection.js:77:17)
    at CopyFilesTask.run (/Users/username/path/to/project/node_modules/laravel-mix/src/tasks/CopyFilesTask.js:16:20)
    at CustomTasksPlugin.runTask (/Users/username/path/to/project/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:46:36)
    at CustomTasksPlugin.runTasks (/Users/username/path/to/project/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:87:21)
    at /Users/username/path/to/project/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:87:58
(Use `node --trace-warnings ...` to show where the warning was created)
(node:54876) 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: 3)

I also tried:

mix.copy('src/.htaccess', 'build')

Which resulted in:

(node:56178) UnhandledPromiseRejectionWarning: Error: EPERM: operation not permitted, unlink '/Users/username/path/to/project/build'
    at Object.unlinkSync (fs.js:1210:3)
    at mayCopyFile (/Users/username/path/to/project/node_modules/fs-extra/lib/copy-sync/copy-sync.js:59:8)
    at onFile (/Users/username/path/to/project/node_modules/fs-extra/lib/copy-sync/copy-sync.js:54:10)
    at getStats (/Users/username/path/to/project/node_modules/fs-extra/lib/copy-sync/copy-sync.js:48:44)
    at startCopy (/Users/username/path/to/project/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
    at handleFilterAndCopy (/Users/username/path/to/project/node_modules/fs-extra/lib/copy-sync/copy-sync.js:33:10)
    at Object.copySync (/Users/username/path/to/project/node_modules/fs-extra/lib/copy-sync/copy-sync.js:26:10)
    at File.copyTo (/Users/username/path/to/project/node_modules/laravel-mix/src/File.js:245:12)
    at FileCollection.copyTo (/Users/username/path/to/project/node_modules/laravel-mix/src/FileCollection.js:83:17)
    at /Users/username/path/to/project/node_modules/laravel-mix/src/FileCollection.js:77:38
    at Array.forEach (<anonymous>)
    at FileCollection.copyTo (/Users/username/path/to/project/node_modules/laravel-mix/src/FileCollection.js:77:17)
    at CopyFilesTask.run (/Users/username/path/to/project/node_modules/laravel-mix/src/tasks/CopyFilesTask.js:16:20)
    at CustomTasksPlugin.runTask (/Users/username/path/to/project/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:46:36)
    at CustomTasksPlugin.runTasks (/Users/username/path/to/project/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:87:21)
    at /Users/username/path/to/project/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:87:58
(Use `node --trace-warnings ...` to show where the warning was created)
(node:56178) 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: 3)

I got the same errors trying to copy a .env file.

I poked around the source for a bit but I couldn’t figure out why dotfiles were being mistaken as directories.

Steps To Reproduce:

  • Install Mix.
  • Create a dotfile at src/.whatever
  • Run mix.copy('src/.whatever', 'build/.whatever')

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
blakewatsoncommented, Apr 4, 2021

For anyone that might be having this problem, I’m working around it by using the .after() hook to run fs.copyFile manually. Something like:

const fs = require('fs');

mix.after(() => {
  return new Promise((resolve, reject) => {
    fs.copyFile('src/.htaccess', 'build/.htaccess', 0, err => {
      if (err) return reject(err);
      resolve();
    });
  });
});
0reactions
u01jmg3commented, Sep 10, 2021

Still having issues with these 2 copies which used to work in Mix v5.

Instead relying on the code from @blakewatson

var sourcePath = 'resources/assets';
var publicPath = '../public_html/assets';

mix.copy(sourcePath + '/.htaccess', publicPath + '/.htaccess')
   .copy('resources/files', '../public_html/files');
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to copy with cp to include hidden files and ... - Super User
This will copy the contents of /etc/skel to /home/user (including hidden files), creating the folder /home/user if it does not exist; however the...
Read more >
copy-files doesn't copy dot-files · Issue #5052 · babel ... - GitHub
Current Behavior. Folders and dot-files are not copied ... I am not being able to copy .eslintrc file to my compiled directory :( ......
Read more >
how to copy or backup files ignoring dot files
The above will list all the files to be archived without actually copying anything. Check that the list is correct, then run it...
Read more >
Unable to copy dot files from external source, using smb
I am using rsync to backup from an ubuntu server to my TNAS, but the copying of any file that starts with a...
Read more >
What's the recommended way to copy multiple dotfiles with ...
I would like to automatically copy all files in the /templates folder, and rename the ones that are prefixed with _. What's the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found