adamreisnz / replace-in-file

A simple utility to quickly replace contents in one or more files
580 stars 65 forks source link

Issue on Windows #183

Closed TomSinclair closed 8 months ago

TomSinclair commented 9 months ago

Hello!

I'm running in to an issue when running a replace on Windows. I have tested on my local Mac and it works fine but on a Windows machine it causes an OS level error.

I am attempting to replace all mentions of a string "/assets/" in multiple places in each file with another string "/static/assets/". I am using the CLI to run the script from a package.json file after some HTML has been compiled.

The node script I am using is:

"path-replace": "replace-in-file --configFile=replace-in-file.js --dry"

On Mac the results are below:

Replacing '/\/assets\//g' with '/static2/assets/'
4 file(s) were changed

But on Windows I receive an OS error "Expected identifier, string or number" Line 5 Char 1

The config file I am using is below:

module.exports = {
  files: "../wwwroot/static/**",
  from: /\/assets\//g,
  to: "/static/assets/",
};

I thought it may be an OS issue with the trailing comma on line 4 but removing that results in a different error "'module' is undefined' Line 1 Char 1

Thank you for any assistance with this :)

adamreisnz commented 8 months ago

Where does the error originate from, what library? If it's not from this library, then I'm afraid there is not much I can do about it. There have been a few other issues previously raised for Windows specific. There is a setting you can use if need be to run this on windows.

See:

If the error is originating from this lib and the above doesn't help, please feel free to reopen this issue.