英文:
Nodemon won't detect changes if I run it with npm run
问题
"scripts": {
"dev": "npx nodemon --watch 'src/**/*.ts' -e ts --exec ts-node --esm src/index.ts"
},
如果我运行 npm run dev
,nodemon 将成功启动,但如果我更新 src 文件夹内的任何 .ts 文件,nodemon 将无法检测到项目中的更改,并且不会重新运行项目。
然而,如果我直接在终端中运行 npx nodemon --watch 'src/**/*.ts' -e ts --exec ts-node --esm src/index.ts
,它也会成功启动,但这次它实际上会检测到 src 文件夹中任何 .ts 文件的更改并重新运行项目。
我有以下结构:
├───🔱 .vscode/
│ └───🔖 types.ts.code-snippets
├───🔱 src/
│ ├───🔱 entities/
│ │ └───...
│ ├───🔱 resolvers/
│ │ └───...
│ └───🔖 index.ts
├───🔖 .gitignore
├───🔖 backend-idea.yml
├───🔖 package-lock.json
├───🔖 package.json
└───🔖 tsconfig.json
我尝试将 'src/**/*.ts'
改为 "./src/**/*.ts"
,它的行为和之前完全相同。
为什么只有在直接在终端中执行时才有效,而不是使用 npm run dev
?我在 Windows 11 上,Node 版本是 v19.9,Powershell 版本是 7.3.6。(当前路径在项目的根目录)
英文:
I have the following command:
"scripts": {
"dev": "npx nodemon --watch 'src/**/*.ts' -e ts --exec ts-node --esm src/index.ts"
},
If I run npm run dev
nodemon will start successfully, but If I update any of my .ts files inside the src folder, nodemon won't detect changes in the project and won't re-run the project.
Nevertheless, If I run npx nodemon --watch 'src/**/*.ts' -e ts --exec ts-node --esm src/index.ts
directly in my terminal, it will start successfully too, but this time it will actually detect changes in any of my .ts file in the src folder and re-run the project.
I have the following structure:
├───📁 .vscode/
│ └───📄 types.ts.code-snippets
├───📁 src/
│ ├───📁 entities/
│ │ └───...
│ ├───📁 resolvers/
│ │ └───...
│ └───📄 index.ts
├───📄 .gitignore
├───📄 backend-idea.yml
├───📄 package-lock.json
├───📄 package.json
└───📄 tsconfig.json
I tried to change 'src/**/*.ts'
to "./src/**/*.ts"
and it worked exactly like before.
What could be the reason it only works If I execute directly in my terminal and not with npm run dev
? I am in Windows 11, Node v19.9, Powershell 7.3.6. (pwd is in the root directory of the project)
答案1
得分: 2
为了使其工作,我不得不将'
替换为\"
和"\
。因此,脚本看起来像这样:
"scripts": {
"dev": "npx nodemon --watch \"src/**/*.ts\" -e ts --exec ts-node --esm src/index.ts"
},
英文:
In order to make it work I had to replace the '
to \"
& "\
. So the script looks like that:
"scripts": {
"dev": "npx nodemon --watch \"src/**/*.ts\" -e ts --exec ts-node --esm src/index.ts"
},
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论