-
-
Save rosszurowski/eee05cebb67fd869b7db1914b844db9c to your computer and use it in GitHub Desktop.
Modifying $PATH in Make on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You can, in fact reference node_modules without the prefix by prepending node_modules to your $PATH with this line: | |
export PATH := ./node_modules/.bin:$(PATH) | |
# But for some reason, on macOS, Make doesn’t recognize the $PATH when it’s the start of a command. | |
# So this rule doesn’t work. It treats `prettier` as a file/directory: | |
format: node_modules | |
@prettier --write . | |
# But this rule does: | |
format: node_modules | |
@true && prettier --write . | |
# Erring on the side of simplicity and clarity, it's probably best to just include the full prefix. |
Thanks @nebbles! And I haven't yet found an incantation that works. When I run this Makefile:
export SHELL := /bin/bash
export PATH := ./node_modules/.bin:$(PATH)
format:
@prettier --write .
I still get the following error:
$ make format
make: prettier: No such file or directory
make: *** [format] Error 1
I've also tried it with SHELL := /bin/bash
, SHELL = /bin/bash
, export SHELL = /bin/bash
and adjusting its positioning relative to the export PATH
call.
Are you running a non-stock version of Make perhaps? Or is there a different incantation to use?
Oo interesting. This is the top of the Makefile I ran:
SHELL=bash
export REACT_APP_GIT_HASH := $(shell git rev-parse HEAD)
export PATH := ./node_modules/.bin:$(PATH)
I'm using stock make, but a bit older
GNU Make 3.81
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On macOS, the path is correctly updated if you've set
SHELL=bash
at the top of the Makefile. I think this keeps the Makefile fairly portable still as most systems already have bash installed too.Loved your post about Makefiles by the way