Skip to content

ts-node should not be default when --import flag is present #2157

@jolyndenning

Description

@jolyndenning
  • Versions: [email protected], [email protected]
  • nodemon -v: 2.0.20
  • Operating system/terminal environment (powershell, gitshell, etc): Mac / VS Code shell
  • Using Docker? What image: No
  • Command you ran: cross-env IS_LOCAL=true \"NODE_OPTIONS=--import ./register-hooks.js\" IS_RUNNING_LOCALLY=true BASEPLATE_ENV=dev PORT=7601 nodemon --signal SIGINT backend/Server.ts --watch backend --watch migrations --watch frontend --watch docs --ext tsx,ts,js,md,mdx,ejs

See related f7816e4 and #2083. In NodeJS 20, it's possible to customize loader hooks via both the --loader and --import flags, but nodemon currently only accounts for the --loader hook

Expected behaviour

When the --import NODE_OPTIONS flag is present, ts-node should not be the default program to execute .ts and .tsx files.

Actual behaviour

When the --import NODE_OPTIONS flag is present, ts-node is the default program to execute .ts and .tsx files. Note that this can be worked around by creating a nodemon.json file with the following:

{
  "execMap": {
    "ts": "node",
    "tsx": "node"
  }
}

Steps to reproduce

  1. Create a .register.mjs file that uses https://github.com/node-loader/node-loader-babel to compile typescript files
import { register } from 'node:module';

register("@node-loader/babel", import.meta.url);
  1. Run a typescript program with nodemon:
"NODE_OPTIONS=--import ./register.mjs" nodemon main.ts

Note the error that occurs:

sh: ts-node: command not found
[nodemon] failed to start process, "ts-node" exec not found
[nodemon] Error
    at Bus.<anonymous> (/Users/joeldenning/code/baseplate-web-app/node_modules/.pnpm/[email protected]/node_modules/nodemon/lib/nodemon.js:158:25)
    at Bus.emit (node:events:526:35)
    at ChildProcess.<anonymous> (/Users/joeldenning/code/baseplate-web-app/node_modules/.pnpm/[email protected]/node_modules/nodemon/lib/monitor/run.js:190:11)
    at ChildProcess.emit (node:events:514:28)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)
[nodemon] 2.0.20
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): backend/**/* migrations frontend/**/* docs/**/*
[nodemon] watching extensions: tsx,ts,js,md,mdx,ejs
--------------
node: v20.8.0
nodemon: 2.0.20
command: /Users/joeldenning/n/bin/node /Users/joeldenning/code/baseplate-web-app/node_modules/nodemon/bin/nodemon.js --dump --signal SIGINT backend/Server.ts --watch backend --watch migrations --watch frontend --watch docs --ext tsx,ts,js,md,mdx,ejs
cwd: /Users/joeldenning/code/baseplate-web-app
OS: darwin arm64
--------------
{
  run: false,
  system: { cwd: '/Users/joeldenning/code/baseplate-web-app' },
  required: false,
  dirs: [
    '/Users/joeldenning/code/baseplate-web-app/backend',
    '/Users/joeldenning/code/baseplate-web-app/frontend',
    '/Users/joeldenning/code/baseplate-web-app/docs'
  ],
  timeout: 1000,
  options: {
    dump: true,
    signal: 'SIGINT',
    watch: [
      'backend',
      'migrations',
      'frontend',
      'docs',
      re: /backend|migrations|frontend|docs/
    ],
    execMap: { py: 'python', rb: 'ruby', ts: 'ts-node' },
    ignore: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**',
      re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/
    ],
    monitor: [
      '/Users/joeldenning/code/baseplate-web-app/backend/**/*',
      'migrations',
      '/Users/joeldenning/code/baseplate-web-app/frontend/**/*',
      '/Users/joeldenning/code/baseplate-web-app/docs/**/*',
      '!**/.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,
    stdin: true,
    runOnChangeOnly: false,
    verbose: false,
    stdout: true,
    watchOptions: {},
    execOptions: {
      script: 'backend/Server.ts',
      exec: 'ts-node',
      args: [],
      scriptPosition: 0,
      nodeArgs: undefined,
      execArgs: [],
      ext: 'tsx,ts,js,md,mdx,ejs',
      env: {}
    }
  },
  load: [Function (anonymous)],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [ '/Users/joeldenning/code/baseplate-web-app/nodemon.json' ],
  watchInterval: null,
  signal: 'SIGINT',
  command: {
    raw: { executable: 'ts-node', args: [ 'backend/Server.ts' ] },
    string: 'ts-node backend/Server.ts'
  }
}
--------------

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions