我正在使用:
我无法使用以下启动文件在断点处停止.调试器运行并附加到端口,但是当我使用断点运行应用程序时,它不会在断点处停止并直接运行.任何有这个工作的人,请指教.
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/src/app.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node.cmd",
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
{
"name": "Attach to Process",
"type": "node",
"request": …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有nodemon的babel-node进行热重新加载.我基本上跟着这个回购.
我的dev
脚本package.json
看起来像这样:
"dev": "nodemon app.js --exec babel-node --presets env"
Run Code Online (Sandbox Code Playgroud)
我的.babelrc
:
{
"presets": ["env"]
}
Run Code Online (Sandbox Code Playgroud)
尽管扩展运算符被列为env预设支持,但在使用此设置时,我得到了一个
SyntaxError:意外的令牌
在开发中运行我的代码时,使用babel-register或babel-node之间有什么区别吗?这两个选项是:
require('babel-register')({
"presets": ["es2015"]
});
在entry-point.js和npm启动脚本 node entry-point.js
只需要npm启动脚本 babel-node entry-point.js --preset=es2015
他们做的完全一样吗?并且推荐的方式是另一种方式吗?
通常要通过命令行启动,我可以输入:
babel-node server.js
Run Code Online (Sandbox Code Playgroud)
当我尝试将其设置为断点以及在我收到的visual studio代码中不起作用时:
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js --debug-brk=31893 --nolazy server.js
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 1: /Applications: is a directory
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 3: /Applications: is a directory
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 4: Dockerfile: command not found
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: syntax error near unexpected token `('
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: ` * when found, before invoking the "real" _babel-node(1) executable.'
Run Code Online (Sandbox Code Playgroud)
我猜测它与从该目录调用可执行文件的事实有关,而不是与server.js文件在同一目录中 - 但我真的不知道.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/server.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": "${workspaceRoot}/node_modules/babel-cli/lib/babel-node.js", …
Run Code Online (Sandbox Code Playgroud) 在我的package.json中,我有一个启动脚本,我正用于我的开发环境.它看起来像这样:
"scripts": {
"dev": "NODE_PATH=src nodemon --watch src/ --exec babel-node src/app.js"
}
Run Code Online (Sandbox Code Playgroud)
当我击中npm run dev
一切时,一切正常,巴贝尔正在发现应有的一切,并且nodemon开始观看.我看到了这个:
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /Users/Jonathan/Documents/swissnet/src/**/*
[nodemon] starting `babel-node src/app.js`
Run Code Online (Sandbox Code Playgroud)
当我在src/-folder节点中保存文件时,将重新启动服务器.但这是我的问题,它重启2-3次......每次我保存一个文件,它看起来像这样:
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/app.js`
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/app.js`
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/app.js`
Run Code Online (Sandbox Code Playgroud)
如果我输入"rs",那么nodemon会按预期重启一次.
我不知道如何解决这个问题,甚至不知道在哪里寻找答案.我试过去谷歌吧.我一直在访问github上的软件包的bug部分...(也许我只是在google搜索).
这是我为同一个问题找到的唯一链接,但它似乎没有答案:Nodemon在使用babel时多次运行保存.
无论如何我尝试了他的脚本,NODE_PATH=src nodemon src --exec babel -w src/ --out-dir build/ --source-maps …
我有一个带有异步 main 方法的节点 js 脚本。有时脚本会正常终止,有时则会挂起。
const main = async () => {
let updates = []
// ... add a bunch of promises to updates
await Promise.all(updates)
}
main()
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么这个脚本有时可能会挂起?尽管它似乎已经运行完成,但它只是没有终止。
使用babel-watch
,通过 Chrome 检查器调试时,我没有可用的源映射。
当运行使用相同的代码babel-node
,具有相同.babelrc
源的地图。
这是我的 .babelrc:
{
"presets": [
["@babel/preset-env", { "targets": { "node": "current" } } ]
],
"sourceMaps": "inline"
}
Run Code Online (Sandbox Code Playgroud)
我如何使源地图可用babel-watch
?
我在安装时遇到问题 babel-node
npm i -g babel-node
> babel-node@6.5.2 postinstall /Users/.../.../node_modules/babel-node
> node message.js; sleep 10; exit 1;
/Users/.../.../node_modules/ssh-key-to-pem/index.js:210
throw new Error('Only RSA and DSA public keys are allowed');
^
Error: Only RSA and DSA public keys are allowed
Run Code Online (Sandbox Code Playgroud) 我想用pm2软件包管理我的节点进程。如果我的代码中没有任何es6语法,那么我不需要添加babel-node,并且没有任何es6语法代码就可以在此代码行中将我的代码与pm2一起运行
pm2 start server.js
Run Code Online (Sandbox Code Playgroud)
但是,一旦我像这样添加es6语法的任何代码行
import express from 'express';
Run Code Online (Sandbox Code Playgroud)
我收到意外的令牌导入错误。
如您所知,要解决此问题,我们必须添加babel-node程序包。
但是当我使用这行命令来编译我的代码时
pm2 start server.js --interpreter babel-node
Run Code Online (Sandbox Code Playgroud)
我得到这个错误
Error: spawn babel-node ENOENT
at _errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我不使用pm2并使用此行代码运行代码
babel-node server.js
Run Code Online (Sandbox Code Playgroud)
一切都好。
在 giltab ci 作业中,我正在运行一个 node.js 脚本,在其中评估一些条件,以及我可能想要强制作业失败。
该脚本是用 es6 编写的,并使用 yarn 和 babel-node 运行yarn babel-node ./script-in-es6.js
。
当条件失败时,我希望工作失败。我已经尝试过以下方法:
throw new Error('job failed')
process.exit(1)
require('shelljs').exit(1)
Run Code Online (Sandbox Code Playgroud)
但这些命令都不足以使作业失败,它总是会成功。有没有正确的方法可以从node.js 成功地使 gitlab 中的作业失败?
babel-node ×10
node.js ×8
babeljs ×4
babel ×2
javascript ×2
babel-cli ×1
debugging ×1
gitlab ×1
gitlab-ci ×1
nodemon ×1
npm ×1
pm2 ×1
process-exit ×1
source-maps ×1