node-dev icon indicating copy to clipboard operation
node-dev copied to clipboard

ESM struggle

Open ricardo-valero opened this issue 2 years ago • 5 comments

Hi, in my package.json I have two scripts, my start script is working, but dev using node-dev isn't

{
    "scripts": {
        "dev": "node-dev --experimental-specifier-resolution=node --loader ts-node/esm/transpile-only src/index.ts",
        "start": "node --experimental-specifier-resolution=node --loader ts-node/esm/transpile-only src/index.ts",
    },
   //...
}

I'm trying to work with ESM, because I need top level await

This is the error:

[ERROR] 19:34:14 RangeError: Unknown module format: null for URL file:///path_to_project/src/index.ts

ricardo-valero avatar May 26 '22 00:05 ricardo-valero

I'm struggling here trying to get node-dev to work with esm. I've tried using ts-node-dev, now I've tried node-dev and it's just been hours of struggles.

Does anyone have a recipe of the changes needed in package.json, tsconfig.json and commands that allow us to have watching/reloading in node-dev?

owenallenaz avatar Jul 19 '22 20:07 owenallenaz

Recommending using tsx watch here.

It's like node-dev in that also only watches files that are imported, but it also supports native ESM.

privatenumber avatar Aug 18 '22 20:08 privatenumber

@privatenumber Do you mean tsx watch or tsc watch?

owenallenaz avatar Sep 15 '22 20:09 owenallenaz

tsx watch. It's linked in my comment.

privatenumber avatar Sep 15 '22 22:09 privatenumber

@privatenumber thank you for mentioning this package! That really helped

EliseyMartynov avatar Oct 06 '22 05:10 EliseyMartynov