open-cli-tools / chokidar-cli

Fast cross-platform cli utility to watch file system changes
https://www.npmjs.com/package/chokidar-cli
MIT License
823 stars 51 forks source link

Error $SHELL environment variable is not set #62

Open mcshaman opened 6 years ago

mcshaman commented 6 years ago

Error $SHELL environment variable is not set is thrown when chokidar-cli is run from the official node.js Docker image. This image doesn't appear to set the SHELL environment variable. This can be fixed by setting the environment variable before running a script.

SHELL=/bin/bash node my-script.js

I understand this may not be chokidar-cli issue but it may be worth mentioning it in documentation.

stephenhebert commented 2 years ago

Setting the shell variable does not seem to resolve the issue. Is there a workaround?

HW13 commented 1 year ago

Depending on the Docker image, bash may not be installed - for example, node-alpine images.

@stephenhebert, have you tried using a different shell?

SHELL=/bin/sh
alexandrubau commented 1 year ago

This may be related to this. As per official Docker documentation:

Unlike the shell form, the exec form does not invoke a command shell. This means that normal shell processing does not happen. For example, CMD [ "echo", "$HOME" ] will not do variable substitution on $HOME. If you want shell processing then either use the shell form or execute a shell directly, for example: CMD [ "sh", "-c", "echo $HOME" ]. When using the exec form and executing a shell directly, as in the case for the shell form, it is the shell that is doing the environment variable expansion, not docker.

I've encountered the same error while setting up a docker-compose.yml file and I fixed it using:

  my-service-name:
    build:
      context: ../
      dockerfile: .docker/node/Dockerfile
    volumes:
      - ../:/var/www/html
    environment:
      SHELL: /bin/ash # Fix chokidar-cli error
    command: ["npm", "run", "start:dev:orm"]

And here is my stard:dev:orm command from package.json:

"scripts":
 "start:dev:orm": "chokidar \"orm/**/*.{ts,json}\" -c \"rimraf dist/orm && npm run build:orm\" --initial",