windows node 开发环境建立

默认分类 2019-06-26 2295 次浏览 次点赞


windows node development env set up

本文详细介绍基于gac-350 门禁的node windows 开发环境的搭建,以及用以该门禁远程编译调试node工程。

gac-350 smart-device-node 工程代码通过gitlab管理.

  • smart-device-node gitlab

    提示:在MyDreamPlus 环境可能连接[aws.ovpn]()连接gitlab),初次下载应用包后需要手动解压根目录下咱node_modules.zip 压缩包。

gac-350 smart-device-node 通过typescript 编码实现,ts通过解释成js后运行。

集成开发环境使用itellij,习惯vs的可以选择vs201x/vscode.

gac-350 门禁通过supervisor守护node 工程运行,程序入口通过supervisor配置文件到npm start 再到 packge.json 包管理的start命令。

supervisor->smart-device-node->npm start->packge.json->node node_modules/cross-env/dist/bin/cross-env.js DEBUG=info:app:*,error:app:* node app/App

install and compile

itellij

itellij 直接通过 ide itellij idea官方下载,直接双击安装,成功安装后破解参考IntelliJ IDEA 最新注册码

  • 修改本机host文件

    0.0.0.0 account.jetbrains.com
    0.0.0.0 www.jetbrains.com
  • 添加注册码

    YZVR7WDLV8-eyJsaWNlbnNlSWQiOiJZWlZSN1dETFY4IiwibGljZW5zZWVOYW1lIjoiamV0YnJhaW5zIGpzIiwiYXNzaWduZWVOYW1lIjoiIiwiYXNzaWduZWVFbWFpbCI6IiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IkZvciBlZHVjYXRpb25hbCB1c2Ugb25seSIsImNoZWNrQ29uY3VycmVudFVzZSI6ZmFsc2UsInByb2R1Y3RzIjpbeyJjb2RlIjoiSUkiLCJwYWlkVXBUbyI6IjIwMTktMTEtMjYifSx7ImNvZGUiOiJBQyIsInBhaWRVcFRvIjoiMjAxOS0xMS0yNiJ9LHsiY29kZSI6IkRQTiIsInBhaWRVcFRvIjoiMjAxOS0xMS0yNiJ9LHsiY29kZSI6IlBTIiwicGFpZFVwVG8iOiIyMDE5LTExLTI2In0seyJjb2RlIjoiR08iLCJwYWlkVXBUbyI6IjIwMTktMTEtMjYifSx7ImNvZGUiOiJETSIsInBhaWRV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dR3lJkZzlpFdiHijoVRdWeSWqM4y0t23c92HXKrgppoSV18XMxrWVdoSM3nuMHwxGhFyde05OdDtLpCv+jlWf5REAHHA201pAU6bJSZINyHDUTB+Beo28rRXSwSh3OUIvYwKNVeoBY+KwOJ7WnuTCUq1meE6GkKc4D/cXmgpOyW/1SmBz3XjVIi/zprZ0zf3qH5mkphtg6ksjKgKjmx1cXfZAAX6wcDBNaCL+Ortep1Dh8xDUbqbBVNBL4jbiL3i3xsfNiyJgaZ5sX7i8tmStEpLbPwvHcByuf59qJhV/bZOl8KqJBETCDJcY6O2aqhTUy+9x93ThKs1GKrRPePrWPluud7ttlgtRveit/pcBrnQcXOl1rHq7ByB8CFAxNotRUYL9IF5n3wJOgkPojMy6jetQA5Ogc8Sm7RG6vg1yow==

node

node 解释器和sdk通过nodejs.org,成功下载后双击默认安装。

run

成功安装itellij后通过New->Project->node->Node.js and NPM 导入代码到工程。

提示:初次下载工程需要手动解压根目录下在的node_modules.zip压缩包。

如果要在windows上面编译工程,需要添加 Run-> Edit Configurationss->+ npm

  • package.json 为工程根目录下的package.json 文件;
  • command 为start
  • Node interprter 为如上node安装路径。
  • 详细配置如下:

    itellij debug node

同时可配置远程机器运行直接配置到gac-350门禁上运行调试。

  • 初次使用该功能需要手动添加node.js 远程解释器插件。

    File->Settings/Preferences (Ctrl+Alt+S)-> Plugins->Maketplace->Node.js Remote Interpreter;

    提示:详细参考Configure Node.js Remote Interpreter Dialog
  • 成功安装node.js 远程插件过后通过Run-> Edit Configurationss->+ Node.js
  • 详细配置如下图:

    远程调试

    提示: 需要提前远程设备root账号和密码,同时允许ssh root账号登录。

troubleshooting

编译失败

Error:(2, 21) TS2307: Cannot find module 'fs'.
Error:(6, 16) TS2503: Cannot find namespace 'NodeJS'.

本地运行提示 Cannot find cross-env.js

internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module 'D:\MyProject\smart-device-node\node_modules\cross-env\dist\bin\cross-env.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

如上文,已经反复提示,初次安装需要手动解压安装根目录下的node_modules.zip 压缩包。

远程调试提示Illegal instruction

/usr/bin/node --inspect=0.0.0.0:57309 --debug-brk app/App node_modules/cross-env/dist/bin/cross-env.js
bash: line 1: 11260 Illegal instruction     env "FORCE_COLOR"="true" "ELECTRON_NO_ATTACH_CONSOLE"="true" "npm_config_color"="always" "DEBUG_COLORS"="true" "MOCHA_COLORS"="1" "DEBUG"="info:app:*,error:app:* " "JETBRAINS_REMOTE_RUN"="1" "COLORTERM"="true" '/usr/bin/node' '--inspect=0.0.0.0:57309' '--debug-brk' 'app/App' 'node_modules/cross-env/dist/bin/cross-env.js'

暂时地,门禁版本过于7,不支持debug功能。

'--inspect=0.0.0.0:57546' 参数无效

https://nodejs.org/zh-cn/docs/guides/debugging-getting-started/

在版本 7 以及更早的版本使用 --debug 或 --debug-brk 开关启动调试时,Node.js 侦听由中断定义的调试命令,TCP 端口上的 V8 调试协议,默认为 5858。任何遵守此协议的调试客户端都可以连接并调试运行这个进程,下面有一些热门的说明。

http://mirrors.sohu.com/debian/pool/main/n/nodejs/

低版本node不支持itellij 调试,需要安装高版本的node->debian Jessie 版本太低不支持高版本node所以需要切换到sid、experimental 源更新libc和gcc->装了高版本node过后发现npm 不在了,通过apt-get install 重新安装了npm。->之后发现electron不能正常启动。


本文由 Jay 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处,点赞2

还不快抢沙发

添加新评论