Skip to content

sh: 1: source: not found with PR #230 on DigitalOcean #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
benloh opened this issue Jul 26, 2024 · 7 comments
Closed

sh: 1: source: not found with PR #230 on DigitalOcean #234

benloh opened this issue Jul 26, 2024 · 7 comments
Assignees

Comments

@benloh
Copy link
Collaborator

benloh commented Jul 26, 2024

Joshua reports that npm run dev does not work on DigitalOcean. It returns an error:

> [email protected] dev
> source ./@build-ursys.sh && brunch w -s
sh: 1: source: not found

echo $SHELL reveals /bin/bash yet source does not work.

However, changing the dev script to use . instead of source seems to work. In package.json from PR #230 change line 10 from "dev": "source ./@build-ursys.sh && brunch w -s", to

"dev": ". ./@build-ursys.sh && brunch w -s"

And then run npm run dev seems to work.

@dsriseah Any suggestions on a proper solution?

@dsriseah
Copy link

dsriseah commented Jul 26, 2024

Copying the additional debug information from Slack...

Did you make any changes to the build process in the last few branches? I tried running the history branch which works fine on my mac on ubuntu and now get this error:

[email protected] dev
> source ./@build-ursys.sh && brunch w -s
sh: 1: source: not found
I can't see anything else I did / changed.
And I see in GIT That Sri changed a bunch of stuff in the package and package.lock et

Sri tests on DO
image

@dsriseah
Copy link

@benloh That is odd since the source command is bash compatible, but it's not POSIX compatible (which is our general target shell for scripting, as this is universal). The POSIX command is dot (the period .) so switching to that makes sense. It is weird that DO doesn't obey the source command, so let me check my install.

@dsriseah
Copy link

dsriseah commented Jul 26, 2024

I pulled netcreate onto the URSYS digital ocean droplet, and confirmed that within the Node script environment that source isn't available. It appears that all npm scripts run under sh, not bash.

The mitigation is to use the dot command, which is available under /bin/sh, as Ben discovered. I'd write it like this:

"dev": ". @build-ursys.sh && brunch w -s"

INTERESTING NOTE

Apparently /bin/sh doesn't refer to a specific shell implementation, but merely means "system shell". It's assumed it's POSIX compatible, but the shell implementation itself depends from OS to OS. See this StackOverflow Discussion "Why does bin/sh act different". Excerpt (emphasis mine):

sh on ubuntu is the dash shell, sh on minix is the ash shell, sh on slackware is the bash shell. And since not too long is sh on OSX also the bash shell

Yikes! So TIL that a best practice is to test against dash for Ubuntu and bash for MacOs. I guess Node thought that specifying /bin/sh would be universal enough for them, but it wasn't a good assumption for us.

Tip

The correct place to check shell would be to do the echo $0 inside of the script line itself in package.json:

 "scripts": {
   "dev": "echo $0 && source ./@build-ursys.sh && brunch w -s",
    ...

That's because this is a command line that is executed by a separate shell, not the user's terminal shell.

@benloh
Copy link
Collaborator Author

benloh commented Aug 19, 2024

Re-opening this...

I just set up a new DO instance with Ubuntu 24.04 and am running into this problem again. Specifically, running ./nc.js --dataset=demo results in the following error:

./nc.js --dataset=demo
...
> [email protected] dev
> . @build-ursys.sh && brunch w -s

sh: 1: .: @build-ursys.sh: not found

It looks like the dev script needs the ./ path for @build-ursys.sh to work. e.g. package.json does need to specify:

  "scripts": {
    "dev": ". ./@build-ursys.sh && brunch w -s",

Adding the path can now run .nc.js correctly.

@dsriseah if you agree, I can make the change. Or you can grab it. Thanks!

@dsriseah
Copy link

Sure, go ahead and make the change. I think this is an issue due to nc.js path setting or something like that; I never use nc.js to launch anything.

@dsriseah
Copy link

oh, I bet it's because this only works in vscode, which has a script that forces the current directory to be in the current PATH. If you are running outside of VSCODE, then the path isn't set this way.

@benloh
Copy link
Collaborator Author

benloh commented Mar 3, 2025

Fixed with #242.

@benloh benloh closed this as completed Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants