open-cli-tools/chokidar-cli

Error $SHELL environment variable is not set

mcshaman opened this issue · 3 comments

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.

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

HW13 commented

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

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",