nx-plugins icon indicating copy to clipboard operation
nx-plugins copied to clipboard

Watch mode crashes on windows

Open zackgomez opened this issue 1 year ago • 3 comments

The plugin consistently crashes for me on windows when I modify a watched file. I believe this is due to some path regularization.

My config

copy({
      resolveFrom: 'cwd',
      assets: [
        {
          from: './assets/profile_pics/*',
          to: './build/www/',
        },
        {
          from: './assets/card_images/*',
          to: './build/www/',
          watch: isDevServer,
        },
        {
          from: './assets/favicon.png',
          to: './build/www/',
        },
      ],
      verbose: true,
      watch: isDevServer,
    }),

Error in verbose mode (with an additional console.log added my me showing the undefined preserved dir structure

[watch-client] i [File Changed] File assets\card_images\ArtArcher.jpg changed, copy operation triggered.
[watch-client] i The from path ./assets/card_images/* of current asset pair doesnot ends with /**/*(.ext),
[watch-client] preservedDirStructure: undefined, globbedFromPath: assets\card_images\ArtArcher.jpg, startFragment: ./assets/card_images, sourcePath: C:\Users\Zack\Programming\mythos\assets\card_images\ArtArcher.jpg
[watch-client] file:///C:/Users/Zack/Programming/mythos/node_modules/esbuild-plugin-copy/dist/index.mjs:55
[watch-client]       preservedDirStructure.slice(1)
[watch-client]                             ^
[watch-client]
[watch-client] TypeError: Cannot read properties of undefined (reading 'slice')
[watch-client]     at copyOperationHandler (file:///C:/Users/Zack/Programming/mythos/node_modules/esbuild-plugin-copy/dist/index.mjs:55:29)      
[watch-client]     at file:///C:/Users/Zack/Programming/mythos/node_modules/esbuild-plugin-copy/dist/index.mjs:140:17
[watch-client]     at Array.forEach (<anonymous>)
[watch-client]     at FSWatcher.<anonymous> (file:///C:/Users/Zack/Programming/mythos/node_modules/esbuild-plugin-copy/dist/index.mjs:139:18)    
[watch-client]     at FSWatcher.emit (node:events:513:28)
[watch-client]     at FSWatcher.emitWithAll (C:\Users\Zack\Programming\mythos\node_modules\chokidar\index.js:540:8)
[watch-client]     at FSWatcher._emit (C:\Users\Zack\Programming\mythos\node_modules\chokidar\index.js:632:8)
[watch-client]     at listener (C:\Users\Zack\Programming\mythos\node_modules\chokidar\lib\nodefs-handler.js:389:18)
[watch-client]     at C:\Users\Zack\Programming\mythos\node_modules\chokidar\lib\nodefs-handler.js:271:49
[watch-client]     at foreach (C:\Users\Zack\Programming\mythos\node_modules\chokidar\lib\nodefs-handler.js:41:5)
[watch-client]
[watch-client] Node.js v18.12.1

Specifically looking at the log I added

preservedDirStructure: undefined, globbedFromPath: assets\card_images\ArtArcher.jpg, startFragment: ./assets/card_images, sourcePath: C:\Users\Zack\Programming\mythos\assets\card_images\ArtArcher.jpg

preservedDirStructure is undefined because the globbedFromPath = assets\card_images\ArtArcher.jpg is missing the prepended ./ and uses windows \ instead of my configs /.

zackgomez avatar Jun 09 '24 21:06 zackgomez

I can fix this locally by preresolving both of the variables

image

I can put up a PR if you would prefer

zackgomez avatar Jun 09 '24 21:06 zackgomez

@zackgomez I am experiencing the same.

Is there any other fix other than modifying this package in node_modules ?

graforlock avatar Sep 01 '24 17:09 graforlock

The correct solution would be to produce a corrected module by either updating this repo or forking and creating a new repo and package.

You could also "vendorize" the source tree with the fix. All of these solutions are much more annoying and less valuable than this repository being updated. It seems unmaintained or very sparsely maintained at best

zackgomez avatar Sep 02 '24 19:09 zackgomez