Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add esm to ts-node flags #312

Open
ricardo-valero opened this issue May 27, 2022 · 11 comments
Open

Add esm to ts-node flags #312

ricardo-valero opened this issue May 27, 2022 · 11 comments

Comments

@ricardo-valero
Copy link

ricardo-valero commented May 27, 2022

I'm trying to run

ts-node-dev --experimental-specifier-resolution=node --esm --transpile-only src/index.ts

I'm getting this message

bad option: --esm

const tsNodeFlags = {

@simllll
Copy link

simllll commented Jun 9, 2022

Just ran into the same issue, any known workaround?

@wclr
Copy link
Owner

wclr commented Jun 9, 2022

Just adding esm flag here won't work (it is not an ts-node API option which is used by this package), need to dig a bit deeper on how to make ESM work correctly.

Doesn't ts-node-dev -r esm work anyway?

@ricardo-valero
Copy link
Author

Running

ts-node-dev -r esm src/index.ts

or

ts-node-dev --experimental-specifier-resolution=node --respawn -r esm src/index.ts

Returns

[INFO] 09:41:12 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.8.1, typescript ver. 4.7.3)
node:internal/modules/cjs/loader:942
  throw err;
  ^

Error: Cannot find module 'esm'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:939:15)
    at Module._load (node:internal/modules/cjs/loader:780:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1282:12)
    at loadPreloadModules (node:internal/bootstrap/pre_execution:582:5)
    at prepareMainThreadExecution (node:internal/bootstrap/pre_execution:96:3)
    at node:internal/main/run_main_module:7:1 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}

Node.js v18.3.0

@wclr
Copy link
Owner

wclr commented Jun 10, 2022

Cannot find module 'esm'

Install esm loader package.

@zemd
Copy link

zemd commented Jun 26, 2022

it is not an ts-node API option which is used by this package

Hi, @wclr!

https://typestrong.org/ts-node/docs/options#esm

ts-node --esm

ts-node does use this option, and my test project works with this flag when using ts-node

@yukha-dw
Copy link

Doesn't ts-node-dev -r esm work anyway?

Is there any update about this method?
I've tried this and the problem still persists

ts-node --esm is indeed working, but without auto-restart feature.

@maxpain
Copy link

maxpain commented Nov 20, 2022

Any updates?
Or maybe alternatives to ts-node-dev?

@DesignByOnyx
Copy link

DesignByOnyx commented Dec 9, 2022

I was able to get it working with ts-node and nodemon. I can't yet speak for the speed, but it works:

npm i typescript ts-node nodemon -D

# this one worked first, but there's a warning about using experimental features
nodemon -I --exec node --experimental-specifier-resolution=node  --loader ts-node/esm ./src/main.ts

# then I got this one to work, a bit shorter and easier to read, no warnings
nodemon --exec ts-node --esm -r dotenv/config src/index.ts

This was taken from this thread: #314

@trim21
Copy link

trim21 commented Dec 29, 2022

you can try https://github.com/esbuild-kit/tsx , it using esbuild, handle file extention (no need --experimental-specifier-resolution=node) and works like --transpile-only

@DesignByOnyx
Copy link

I can report that tsx works like a charm! Thanks so much! The nodemon scripts from my previous comment can be reduced to this:

npm i tsx -D

tsx watch ./src/main.ts

@irg1008
Copy link

irg1008 commented Feb 1, 2023

you can try https://github.com/esbuild-kit/tsx , it using esbuild, handle file extention (no need --experimental-specifier-resolution=node) and works like --transpile-only

You are a life saver my friend, spent the last 4 hours on this

thewilkybarkid added a commit to PREreview/prereview.org that referenced this issue Jun 13, 2024
This change replaces ts-node-dev with tsx.

Note that tsx can't watch arbitrary files, so changes to the local .env no longer restart the server.

Refs #1750 wclr/ts-node-dev#312, privatenumber/tsx#181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants