0

I'm trying to run a lessc PowerShell commandline in my package.json. So in my scripts section I have something like that:

Get-ChildItem *.less -Recurse | ForEach-Object {lessc $_.FullName > $_.BaseName.css}

but it's giving me the following error:

'Get-ChildItem' is not recognized as an internal or external command

while this is executing normally in PowerShell

Get-ChildItem *.less -Recurse | ForEach-Object {echo $_.Name}

A plain lessc command also works as expected.

Any ideas?

Also check this question that have another solution for this.

Community
  • 1
  • 1
Argiropoulos Stavros
  • 9,436
  • 11
  • 61
  • 79

1 Answers1

2

The error message suggests that you're not running the statement in PowerShell. lessc is a node.js application, not a PowerShell command, so it's unsurprising that it works when used by itself.

To be able to use PowerShell cmdlets you need to run the statement in PowerShell, e.g. like this:

powershell.exe -ExecutionPolicy Bypass -Command "Get-ChildItem  *.less -recurse | Foreach-Object{ lessc $_.FullName > $_.BaseName.css }"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • A powershell.exe -ExecutionPolicy Bypass -Command is also needed before the Foreach command.Thanks – Argiropoulos Stavros Jan 19 '16 at 10:57
  • 1
    @ArgiropoulosStavros No. You run the entire statement in a single `powershell.exe` process. If you need a second one you most likely have an issue with quotes or unescaped characters. For further troubleshooting you need to show the actual content of your `package.json`, not just the command you're trying to run. – Ansgar Wiechers Jan 19 '16 at 11:06