Command Line Problem

I have this really strange problem that I am facing.
Hopefully someone can shed some light why it is doing that.

Inside visual studio code. I am trying to run a npm command.

: npm run start-api

where start-api is executing some form command line.

"start-api" : "cd packages/api; yarn start"

Here is the strange part.
Inside visual studio code. This won’t run.
It outputs error that says “The system cannot find the path specified”

However, if I type “cd packages/api; yarn start” directly into the command line.
It will run it no problem!!

What is going on!!!

Does this work:

"start-api" : "cd packages/api && yarn start"
1 Like

Yes that does work.
The problem here is that the dev lead don’t wait it like that.
He uses mac while I am on window, while some people are on linux.

He provided a solution to use cross-env npm package. Which I don’t see how it solves the problem.

The cd folder && should work on any Windows or Mac or Linux command line, that’s why it’s allowed in the NPM script. The cd folder; will not, which is why it isn’t allowed. Also, I don’t see how that’s what you want anyway, because ; just seperates commands, so the entire command won’t fail if the cd command fails (cd fails -> yarn start then still runs but in the wrong folder).

Lead is suggesting cross-env so that there are no cross-platform issues (which there currently are if you want to keep using ;)

1 Like

If && works on all three platform. Why do we not use && instead of ;
I am really confused about this point. Can you clarify this?

If the entire command won’t fail, why execute the 2nd or 3rd command if they depend on the 1st command to work.

I tried using cross-env in the project and read the documentation. Which only solves environmental variable issues which is not the problem. Perhaps I am missing something that cross-env is doing that I am not aware of.

I’m extremely confused here: you said in your original post that you were using the semicolon, I’m suggesting using &&. I don’t know why you want to use the semicolon, and why you don’t want to use &&

Perhaps I miss read your previous post.

I get why the use of &&, I am all for it.

When I used this method over the ;
The lead doesn’t want && and wants to maintain it using a ;
To him, && and ; are both doing the same thing.

My dilemma here is, how does cross-env even solve this problem of maintaining the usage of ; in a npm script.

1 Like

The lead doesn’t know the first thing about shell scripting. You need to start ignoring everything he says. Regardless, if the directory exists already, they will be equivalent, and you have a different problem.

2 Likes

I like your answer LOL.
I might have to confront the lead on this matter.
Or simply ask for clarification why he thinks cross-env would solve the problem.

I wouldn’t ignore him regarding using cross-env however – it comes in handy. It could be cmd.exe doesn’t like the forward slash in the path and cross-env is fixing that somehow. It’s been so long that I’ve done any dev on windows that wasn’t already cross-platform (namely Java) so I can’t remember how it behaves. npm really should ship with cross-env, it seems to be the very first support tool I see most packages use.

By adding cross-env into the project I ran into another problem with webpack and configuration AND typescript unable to recognize imports.

Ah I see: yeah, lead should probably read at least some bash documentation, they don’t know what they’re talking about. Not sure re cross-env (sorry, I should have clarified a bit more re usage, you’re absolutely correct that it doesn’t quite make sense in this context, I’d forgotten what exactly it did). It shouldn’t cause the issue you’re talking about unless there’s another scripting/env var issue that’s been hidden until you installed it, not sure how that would would be caused. Is it all throwing any specific error?

1 Like

I have solved the problem.

I have broken down the command to their individual component and uses a webpack plugin to deal with each command so we don’t have the issues of chaining commands together.

1 Like