Azure Node.js API应用运行时失败排查(疑似Node.js版本问题)
Node.js API部署Azure:Linux环境模块导入失败,切换Windows解决
最近踩了个Azure部署Node.js API的坑,跟大伙唠唠整个排查和解决过程:
我有个通过VSO(Visual Studio Online)持续部署的Node.js API应用,本地运行完全正常,但部署到Azure后,导入express这类模块时直接运行失败。
一开始我以为是依赖没装全,特意通过Kudo控制台在Azure机器上手动安装了express,结果问题依然没解决,抛出的错误信息如下:
Application has thrown an uncaught exception and is terminated: SyntaxError: Unexpected token ILLEGAL at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (D:\home\node_modules\tedious\lib\tedious.js:4:29) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12)
后来查资料看到有人建议使用Node.js 4以上版本,我赶紧检查了自己的package.json,明明已经明确指定了Node.js 6.11版本,配置内容如下:
{ "name": "my_API_Service", "engines": { "node": "6.11", "npm": "1.1.65" }, "version": "1.0.0", "description": "", "main": "MyService.js", "dependencies": { "async": "^2.6.0", "body-parser": "^1.18.2", "express": "^4.16.2", "http": "0.0.0", "sequelize": "^4.28.6", "swaggerize-express": "^4.0.5", "swaggerize-ui": "^1.0.1", "tedious": "^2.1.5" }, "devDependencies": { "gulp": "^3.9.1", "gulp-util": "^3.0.8" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "https://<my_api_service_url>" }, "author": "", "license": "ISC" }
试了各种调试方法都没搞定,最后抱着死马当活马医的心态,把Azure应用的操作系统从Linux改成了Windows——结果居然直接成功运行了!虽然我原本是计划在Linux环境下运行的,但过程中遇到的问题实在棘手,暂时先切换到Windows环境保证服务正常可用。
内容的提问来源于stack exchange,提问作者AlvinfromDiaspar
相关产品推荐
相关产品推荐

