Search code examples
node.jsangularnode-sass

Rebuilding node-sass throws syntax invalid error


I've been trying to serve an Angular webpage but it won't compile saying that it can't find node-sass module and after searching through stack overflow I find out that I should try to rebuild the module but when I do it I get a Python syntax error as shown below. I have Python version 3.8.3 and I've tried to reinstall node and angular CLI but with no avail. Do you have any idea on how can I solve this issue?

bash> npm rebuild node-sass
[...]
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\rmsegec\AppData\Local\Programs\Python\Python38\python.exe -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                       ^
gyp ERR! stack SyntaxError: invalid syntax
[...]

this is the Angular version that I've setup:

Angular CLI: 10.0.1
Node: 10.16.3
OS: win32 x64

Angular: 7.2.16
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: <error>

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.10
@angular-devkit/build-angular     0.13.10
@angular-devkit/build-optimizer   0.13.10
@angular-devkit/build-webpack     0.13.10
@angular-devkit/core              7.3.10
@angular-devkit/schematics        10.0.1
@angular/cdk                      7.3.7
@angular/cli                      10.0.1
@angular/material                 7.3.7
@ngtools/webpack                  7.3.10
@nguniversal/express-engine       8.2.6
@schematics/angular               10.0.1
@schematics/update                0.1000.1
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.0

Solution

  • I'm not sure what cause the problem that I had but I've managed to get through it. I had to configure npm to use python 2, install Visual Studio 2017 tools and install manually the angular package @angular-devkit/build-angular even though it is already been referenced in package.json.

    PS: Strangely this same projects works on my friend computer that has just Visual Studio 2019 installed.