Search code examples
powershelluglifyjs

type command (Powershell) throws 'A positional parameter cannot be found that accepts argument' error


I'm trying to use 'uglifyjs' in order to minify all of my javascript files into one '.js' file in order to get the karma ng-scenario e2e testing to function properly. However when I input this

type My.js MyLogon.js MyMenu.js Common\directives\BaseDirectives.js Common\factories\BaseFactories.js Module\AccountConfirmationModule.js Module\AccountModule.js Module\ApplicationModule.js Module\ApplicationRoleModule.js Module\HeaderModule.js Module\Index.js Module\LogOnModule.js Module\PasswordModule.js Module\QAModule.js Module\UsernameModule.js > files.min.js | uglifyjs -o files.min.js

I get the following error

Get-Content : A positional parameter cannot be found that accepts argument 'MyLogon.js'. At line:1 char:5

What am I doing wrong?


Solution

  • The type command in Cmd shell supports typing multiple files at the same time. File names are just space separated. In Powershell, type is an alias for Get-Content. It supports multiple source files, but doesn't use space separation. An array is needed, as specified by the -Path parameter that supports a String array:

    man type    
    Get-Content [-Path] <string[]> [-Credential <PSCredential>] ...
    

    Try passing the cmdlet an array of file names. Like so,

    type @("My.js", "MyLogon.js", "MyMenu.js")  | uglifyjs -o files.min.js