title: Node.JS: Trying to run docker project with docker-compose up exits due to node-sass and node-gyp
body: <p>I'm trying to run one of my Docker work projects from MacBook Air M1 and I'm getting the following error while executing <code>docker-compose up</code>. Apparently <strong>it can't find the python installation</strong>, even though I can do both <code>python --version</code> and <code>python3 --version</code> from terminal. I'm relatively new to Docker but I tried to troubleshoot every possible thing to solve this error</p>
  <pre><code>#8 91.79 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
  #8 91.79 error /app/node_modules/node-sass: Command failed.
  #8 91.79 Exit code: 1
  #8 91.79 Command: node scripts/build.js
  #8 91.79 Arguments: 
  #8 91.79 Directory: /app/node_modules/node-sass
  #8 91.79 Output:
  #8 91.79 Building: /usr/local/bin/node /app/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
  #8 91.79 gyp info it worked if it ends with ok
  #8 91.79 gyp verb cli [
  #8 91.79 gyp verb cli   '/usr/local/bin/node',
  #8 91.79 gyp verb cli   '/app/node_modules/node-gyp/bin/node-gyp.js',
  #8 91.79 gyp verb cli   'rebuild',
  #8 91.79 gyp verb cli   '--verbose',
  #8 91.79 gyp verb cli   '--libsass_ext=',
  #8 91.79 gyp verb cli   '--libsass_cflags=',
  #8 91.79 gyp verb cli   '--libsass_ldflags=',
  #8 91.79 gyp verb cli   '--libsass_library='
  #8 91.79 gyp verb cli ]
  #8 91.79 gyp info using node-gyp@7.1.2
  #8 91.79 gyp info using node@16.13.0 | linux | arm64
  #8 91.79 gyp verb command rebuild []
  #8 91.79 gyp verb command clean []
  #8 91.79 gyp verb clean removing &quot;build&quot; directory
  #8 91.79 gyp verb command configure []
  #8 91.79 gyp verb find Python Python is not set from command line or npm configuration
  #8 91.79 gyp verb find Python Python is not set from environment variable PYTHON
  #8 91.79 gyp verb find Python checking if &quot;python3&quot; can be used
  #8 91.79 gyp verb find Python - executing &quot;python3&quot; to get executable path
  #8 91.79 gyp verb find Python - &quot;python3&quot; is not in PATH or produced an error
  #8 91.79 gyp verb find Python checking if &quot;python&quot; can be used
  #8 91.79 gyp verb find Python - executing &quot;python&quot; to get executable path
  #8 91.79 gyp verb find Python - &quot;python&quot; is not in PATH or produced an error
  #8 91.79 gyp verb find Python checking if &quot;python2&quot; can be used
  #8 91.79 gyp verb find Python - executing &quot;python2&quot; to get executable path
  #8 91.79 gyp verb find Python - &quot;python2&quot; is not in PATH or produced an error
  #8 91.79 gyp ERR! find Python 
  #8 91.79 gyp ERR! find Python Python is not set from command line or npm configuration
  #8 91.79 gyp ERR! find Python Python is not set from environment variable PYTHON
  #8 91.79 gyp ERR! find Python checking if &quot;python3&quot; can be used
  #8 91.79 gyp ERR! find Python - &quot;python3&quot; is not in PATH or produced an error
  #8 91.79 gyp ERR! find Python checking if &quot;python&quot; can be used
  #8 91.79 gyp ERR! find Python - &quot;python&quot; is not in PATH or produced an error
  #8 91.79 gyp ERR! find Python checking if &quot;python2&quot; can be used
  #8 91.79 gyp ERR! find Python - &quot;python2&quot; is not in PATH or produced an error
  #8 91.79 gyp ERR! find Python 
  #8 91.79 gyp ERR! find Python **********************************************************
  #8 91.79 gyp ERR! find Python You need to install the latest version of Python.
  #8 91.79 gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
  #8 91.79 gyp ERR! find Python you can try one of the following options:
  #8 91.79 gyp ERR! find Python - Use the switch --python=&quot;/path/to/pythonexecutable&quot;
  #8 91.79 gyp ERR! find Python   (accepted by both node-gyp and npm)
  #8 91.79 gyp ERR! find Python - Set the environment variable PYTHON
  #8 91.79 gyp ERR! find Python - Set the npm configuration variable python:
  #8 91.79 gyp ERR! find Python   npm config set python &quot;/path/to/pythonexecutable&quot;
  #8 91.79 gyp ERR! find Python For more information consult the documentation at:
  #8 91.79 gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
  #8 91.79 gyp ERR! find Python **********************************************************
  #8 91.79 gyp ERR! find Python 
  #8 91.79 gyp ERR! configure error 
  #8 91.79 gyp ERR! stack Error: Could not find any Python installation to use
  #8 91.79 gyp ERR! stack     at PythonFinder.fail (/app/node_modules/node-gyp/lib/find-python.js:302:47)
  #8 91.79 gyp ERR! stack     at PythonFinder.runChecks (/app/node_modules/node-gyp/lib/find-python.js:136:21)
  #8 91.79 gyp ERR! stack     at PythonFinder.&lt;anonymous&gt; (/app/node_modules/node-gyp/lib/find-python.js:179:16)
  #8 91.79 gyp ERR! stack     at PythonFinder.execFileCallback (/app/node_modules/node-gyp/lib/find-python.js:266:16)
  #8 91.79 gyp ERR! stack     at exithandler (node:child_process:404:5)
  #8 91.79 gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:416:5)
  #8 91.79 gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
  #8 91.79 gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
  #8 91.79 gyp ERR! stack     at onErrorNT (node:internal/child_process:477:16)
  #8 91.79 gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
  #8 91.79 gyp ERR! System Linux 5.10.47-linuxkit
  #8 91.79 gyp ERR! command &quot;/usr/local/bin/node&quot; &quot;/app/node_modules/node-gyp/bin/node-gyp.js&quot; &quot;rebuild&quot; &quot;--verbose&quot; &quot;--libsass_ext=&quot; &quot;--libsass_cflags=&quot; &quot;--libsass_ldflags=&quot; &quot;--libsass_library=&quot;
  #8 91.79 gyp ERR! cwd /app/node_modules/node-sass
  #8 91.79 gyp ERR! node -v v16.13.0
  #8 91.79 gyp ERR! node-gyp -v v7.1.2
  #8 91.79 gyp ERR! not ok 
  #8 91.79 Build failed with error code: 1
  </code></pre>
  <p>I tried all of the things that the error suggests - setting the path variable of the python, and trying to set NPM's config to the python's path but no luck...</p>
  <p>I also tried downgrading node to v16, as node-sass 6.0.1 is not compatible with node v17 <a href="https://github.com/sass/node-sass" rel="nofollow noreferrer">according to the docs</a></p>
  <p>I have python 3.9.8 installed via homebrew, and running <code>which python3</code> outputs <code>/opt/homebrew/bin/python3</code></p>
  <p><code>node -v</code>: <strong>v16.13.0</strong></p>
  <p><code>npm -v</code>: <strong>v8.1.0</strong></p>
  <p><code>echo $PATH</code>: <code>/Library/Frameworks/Python.framework/Versions/3.10/bin /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin</code></p>
  <p><code>npm config list</code>:</p>
  <pre><code>
  prefix = &quot;/opt/homebrew&quot; 
  
  ; &quot;global&quot; config from /opt/homebrew/etc/npmrc
  
  ; python = &quot;/opt/homebrew/opt/python@3.9/libexec/bin&quot; ; overridden by user
  
  ; &quot;user&quot; config from /Users/**username**/.npmrc
  
  python = &quot;/opt/homebrew/opt/python@3.9/libexec/bin&quot; 
  </code></pre>