Windows环境使用命令npx nodemon --exec babel-node src/index.js监听js文件变化报错,监听不生效
Windows环境使用命令npx nodemon --exec babel-node src/index.js监听js文件变化报错,监听不生效
F:\hyworkspace\study\koa_p1>npx nodemon --exec babel-node src/index.js
[nodemon] 2.0.9
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node src/index.js`
[nodemon] restarting due to changes...
(node:7432) UnhandledPromiseRejectionWarning: Error: Command failed: wmic process where (ParentProcessId=2452) get ProcessId 2> nul
at checkExecSyncError (child_process.js:611:11)
at execSync (child_process.js:647:15)
at kill (F:\hyworkspace\study\koa_p1\node_modules\nodemon\lib\monitor\run.js:337:26)
at Function.run.kill (F:\hyworkspace\study\koa_p1\node_modules\nodemon\lib\monitor\run.js:425:7)
at Bus.<anonymous> (F:\hyworkspace\study\koa_p1\node_modules\nodemon\lib\monitor\run.js:495:7)
at Bus.emit (events.js:327:22)
at restartBus (F:\hyworkspace\study\koa_p1\node_modules\nodemon\lib\monitor\watch.js:228:7)
at FSWatcher.filterAndRestart (F:\hyworkspace\study\koa_p1\node_modules\nodemon\lib\monitor\watch.js:212:16)
at FSWatcher.emit (events.js:315:20)
at FSWatcher.emitWithAll (F:\hyworkspace\study\koa_p1\node_modules\chokidar\index.js:540:8)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:7432) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function w
ithout a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection
, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7432) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled wil
l terminate the Node.js process with a non-zero exit code.
之前未使用babel-node时,代码未改成es6语法时,运行npx src/index.js可正常监听js文件变化
package.json如下:
{
"name": "koa_p1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon --exec babel-node src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@koa/cors": "^3.1.0",
"koa": "^2.13.1",
"koa-body": "^4.2.0",
"koa-combine-routers": "^4.0.2",
"koa-helmet": "^6.1.0",
"koa-json": "^2.0.2",
"koa-router": "^10.0.0",
"koa-static": "^5.0.0"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/node": "^7.14.7",
"@babel/preset-env": "^7.14.7",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^4.0.0-alpha.0",
"cross-env": "^7.0.3",
"nodemon": "^2.0.9",
"webpack": "^5.41.1",
"webpack-cli": "^4.7.2",
"webpack-node-externals": "^3.0.0"
}
}
webpack.config.json如下:
const path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const WebpackNodeExternals = require('webpack-node-externals');
const config = {
target:'node',
mode:'development',
entry:[path.join(__dirname,'src/index.js')],
output:{
filename:'[name].bundle.js',
path:path.join(__dirname,'./dist')
},
module:{
rules:[
{
test:/\.(js|jsx)$/,
loader:'babel-loader',
exclude:path.join(__dirname,'./node_modules')
}
]
},
externals:[WebpackNodeExternals()],
plugins:[new CleanWebpackPlugin()],
node:{
//console:true,
global:true,
//process:true,
//Buffer:true,
__dirname:true,
__filename:true,
//setImmediate:true,
//path:true
}
}
module.exports = config
28
收起
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星