Node.js issue :: Angular is not defined :: cannot

2019-07-14 12:19发布

Issue: after generating and starting my new jHipster API in the browser I got the following issue:

Uncaught ReferenceError: angular is not defined

Before the generation I installed the latest:

  • node.js
  • yo
  • bower
  • grunt-cli according to the guidelines

During the generation I got the following warning and errors:

I'm all done. Running npm install & bower install for you to install the required dependencies. If this fails, try running the command yourself.

bufferutil@1.2.1 install K:\work\HP_AIC_WebAdmin_Customization\workspace\aicwebadminapi\node_modules\bufferutil node-gyp rebuild K:\work\HP_AIC_WebAdmin_Customization\workspace\aicwebadminapi\node_modules\bufferutil>if not defined npm_config_node_gyp (node "C:\Users\korban\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node rebuild ) gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable. gyp ERR! stack at failNoPython (C:\Users\korban\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:401:14) gyp ERR! stack at C:\Users\korban\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:356:11 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:82:15) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\korban\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" gyp ERR! cwd K:\work\HP_AIC_WebAdmin_Customization\workspace\aicwebadminapi\node_modules\bufferutil gyp ERR! node -v v5.3.0 gyp ERR! node-gyp -v v3.2.1 gyp ERR! not ok npm WARN install:bufferutil@1.2.1 bufferutil@1.2.1 install: node-gyp rebuild npm WARN install:bufferutil@1.2.1 Exit status 1

utf-8-validate@1.2.1 install K:\work\HP_AIC_WebAdmin_Customization\workspace\aicwebadminapi\node_modules\utf-8-validate node-gyp rebuild K:\work\HP_AIC_WebAdmin_Customization\workspace\aicwebadminapi\node_modules\utf-8-validate>if not defined npm_config_node_gyp (node "C:\Users\korban\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node rebuild ) gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable. gyp ERR! stack at failNoPython (C:\Users\korban\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:401:14) gyp ERR! stack at C:\Users\korban\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:356:11 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:82:15) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\korban\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" gyp ERR! cwd K:\work\HP_AIC_WebAdmin_Customization\workspace\aicwebadminapi\node_modules\utf-8-validate gyp ERR! node -v v5.3.0 gyp ERR! node-gyp -v v3.2.1 gyp ERR! not ok npm WARN install:utf-8-validate@1.2.1 utf-8-validate@1.2.1 install: node-gyp rebuild npm WARN install:utf-8-validate@1.2.1 Exit status 1 npm WARN optional Skipping failed optional dependency /chokidar/fsevents: npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.6 bower angular-aria#1.4.8 ENOGIT git is not installed or not in the PATH Running "ngconstant:dev" (ngconstant) task Creating module aicwebadminapiApp at src/main/webapp/scripts/app/app.constants.js...OK

Running "wiredep:app" (wiredep) task Warning: Error: Cannot find where you keep your Bower packages. Use --force to continue.

Aborted due to warnings.

I made long investigations about the:

  • node_gyp vs Python issue
  • "cannot find bower packages' issue
  • "angular is not defined" issue

but I didn't find a working solution.

Note: mvn clean install and mvn spring-boot:run are running successfully!

If you have any useful thoughts to share about this I would really appreaciate it!

Thank you for your help in advance!

@@@@@@@@@@@@@@@@@@@@@@@@

Final solution

Fix for node_gyp vs Python issue:

  • Downgrade to: Node.js 4.2.3 LTS and npm 2.14.7,
  • install Python 2.7.10 and Visual Studio Express (www.microsoft.com/en-gb/download/details.aspx?id=44914) as well (see node-gyp dependencies:github.com/nodejs/node-gyp#installation)

Fix for "cannot find bower packages' issue and "angular is not defined" issue:

Note: First of all use rff-doctor(github.com/rakuten-frontend/rff-doctor) to verify system configuration for using Yeoman, Grunt and Bower etc. It will show you what is missing and how can you purchase it/them.

What was missing in my case:

  • installing Git(git-scm.com/downloads) and setting it for using https instead of git with the following command: git config --global url."https://".insteadOf git://
  • installing Ruby(www.ruby-lang.org/) and adding it to the PATH
  • installing Sass using gem: gem install sass and addig it to the PATH

1条回答
干净又极端
2楼-- · 2019-07-14 12:50

Few advices for setting up your NodeJS environment on Windows:

  • don't install last NodeJS release, rather install the latest LTS release (Long Term Support)
  • don't use npm 3 yet
  • don't use deep project folder path (like "K:\work\HP_AIC_WebAdmin_Customization\workspace\aicwebadminapi\") as npm may hit Windows maximum path length for your node_modules content.
  • install Python 2.x not 3.x

Consider using nodist or another nvm-like tool to install node.

You must also solve the git error, bower needs git for some modules not found in npm registry. You must fix your environment by installing git and making sure that the 'git' command is available in your path before retrying 'bower install command'. Some git is correctly installed but cannot work because it is blocked by a corporate firewall.

You could also try to run a diagnostic tool like rff-doctor to test your environment for git, grunt, bower and node. Don't follow its recommendation about Ruby and SASS as JHipster does not require them (it uses libsass through grunt/gulp).

查看更多
登录 后发表回答