1

I have the following entry for the scripts key/property in my package.json

"stop": "source .env && yarn doc:stop && lsof -t -i tcp:$EXPRESS_PORT | xargs kill 2> /dev/null && pgrep -f $(pwd) | xargs kill 2> /dev/null",

It does not work when I execute

yarn stop

It throws the following error

/bin/sh: 1: source: not found

But I can call execute directly from the Ubuntu command terminal with no error

source .env

I get the same error when using . (dot) instead of source.

/bin/sh: 1: .: .env: not found

How can I fix?

Thanks

RobC
  • 22,977
  • 20
  • 73
  • 80
Juan Pablo Fernandez
  • 2,408
  • 3
  • 18
  • 32

2 Answers2

0

I think there are two alternatives:

  1. At your stop script definition use bash:

"stop" : "bash -ac ' LOCATION="."; source .env; echo $REACT_APP_ENV; unset IFS' && ...etc"

  1. Add export at your .env, see more here

The third and final alternative is that your file is not realy there, you can verify using ls -la | grep .env

  • I am sure the file exists. I tested your option 1 but it did not work. – Juan Pablo Fernandez Jul 02 '20 at 23:34
  • @JuanPabloFernandez I got, I have an example using cat and cypress, could you try? ```"cy:open": "export $(cat .env | xargs) && CYPRESS_CLIENT=${REACT_APP_KC_ENV} npx cypress open",``` – Wellington Oliveira Jul 03 '20 at 02:16
  • I got the following output yarn run v1.21.1 $ export $(cat .env | xargs) && CYPRESS_CLIENT=${REACT_APP_KC_ENV} npx cypress open xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option /bin/sh: 1: export: #: bad variable name error Command failed with exit code 2. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. – Juan Pablo Fernandez Jul 03 '20 at 04:15
0

Seems like using . .env would work See: https://stackoverflow.com/a/45089609/5155484 and https://wiki.ubuntu.com/DashAsBinSh#source

William Desportes
  • 1,412
  • 1
  • 22
  • 31