npmnodemonts-node

Nodemon won't detect changes if I run it with npm run


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)


Solution

  • 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"
      },