remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development
http://nodemon.io/
MIT License
26.21k stars 1.72k forks source link

can't restart by use node --loader(ts-node/esm) #2104

Closed lqzhgood closed 1 year ago

lqzhgood commented 1 year ago

Expected behaviour

change files to restart

Actual behaviour

change files not restart

Steps to reproduce

package.json

{
    "name": "name",
    "version": "1.0.0",
    "main": "index.ts",
    "type": "module",  <-- esm
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {},
    "devDependencies": {
        "ts-node": "^10.9.1"
    }
}

index.ts

console.log('1', 1);

run command nodemon --exec "node --inspect --loader ts-node/esm ./index.ts" to start nodemon

change index.ts to

console.log('1', 1);
console.log('2', 2);

the nodemon not restart server


dump ``` cwd: E:\c OS: win32 x64 -------------- { run: false, system: { cwd: 'E:\\c' }, required: false, dirs: [ 'E:\\c' ], timeout: 1000, options: { exec: 'node --inspect --loader ts-node/esm ./index.ts', dump: true, ignore: [ '**/.git/**', '**/.nyc_output/**', '**/.sass-cache/**', '**/bower_components/**', '**/coverage/**', '**/node_modules/**', re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/ ], watch: [ '*.*', re: /.*\..*/ ], monitor: [ '*.*', '!**/.git/**', '!**/.nyc_output/**', '!**/.sass-cache/**', '!**/bower_components/**', '!**/coverage/**', '!**/node_modules/**' ], ignoreRoot: [ '**/.git/**', '**/.nyc_output/**', '**/.sass-cache/**', '**/bower_components/**', '**/coverage/**', '**/node_modules/**' ], restartable: 'rs', colours: true, execMap: { py: 'python', rb: 'ruby', ts: 'ts-node' }, stdin: true, runOnChangeOnly: false, verbose: false, signal: 'SIGUSR2', stdout: true, watchOptions: {}, execOptions: { script: null, exec: 'node --inspect --loader ts-node/esm ./index.ts', args: [], scriptPosition: null, nodeArgs: undefined, execArgs: [], ext: 'js,mjs,json', env: {} } }, load: [Function (anonymous)], reset: [Function: reset], lastStarted: 0, loaded: [], watchInterval: null, signal: 'SIGUSR2', command: { raw: { executable: 'node --inspect --loader ts-node/esm ./index.ts', args: [] }, string: 'node --inspect --loader ts-node/esm ./index.ts' } } ```
github-actions[bot] commented 1 year ago

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing <3

lqzhgood commented 1 year ago

No one has the same problem?

remy commented 1 year ago

It's because you've taken over the exec command and nodemon doesn't know what extension to look for, so it defaults to it's normal defaults (json, js).

Typically the exec is used for the program not the full command. So if you change your command to the following, nodemon is able to detect that you're watching the .ts file type and reloads as expected:

$ nodemon --exec "node --inspect --loader ts-node/esm" ./index.ts

The only difference here is that I've moved the filename out of the exec.

lqzhgood commented 1 year ago

Thank you for your explanation, I understand.

So the following command is also valid.

nodemon -e "ts" --exec "node --inspect --loader ts-node/esm  ./index.ts"