0

as a simple example i have two Javascript files.

toAppend.js:

console.log("appended content");

main.js

console.log("main content");

when i run:

type toAppend.js >> main.js

in my power shell, it copies over a bunch of invalid chars, in between each letter. see image. invalid chars

second, when i try to add this command to an NPM script, it says i have the incorrect syntax.

Any idea why this issue is occuring? since i'm using windows, i suppose the shell used to execute npm would be cmd.exe

  • 1
    The file redirection operators in PowerShell (`>` and `>>`) always use UTF16 encoding. Try `type toAppend.js |Add-Content main.js` instead – Mathias R. Jessen Sep 24 '20 at 00:42
  • 1
    @Mathis is correct, but just to clarify: UTF-16LE is used in _Windows PowerShell_, whereas BOM-less UTF-8 is used in PowerShell [Core] v6+ - in neither case is the target file's existing character encoding considered. See the "Inconsistent default encoding behavior in Windows PowerShell" section of the linked answer. As an aside: `type` is a built-in alias for the [`Get-Content`](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-content) cmdlet, and `>>` is _in effect_ the same as `... | Out-File -Append` – mklement0 Sep 24 '20 at 01:01

0 Answers0