lukeed / tsm

TypeScript Module Loader
MIT License
1.19k stars 19 forks source link

Node.js 20 support #46

Open ai opened 1 year ago

ai commented 1 year ago

Reproduction:

echo "import { test } from 'uvu'; test('one', () => {}); test.run()" > index.test.ts
npm install uvu tsm
npx tsm ./node_modules/.bin/uvu

Node.js 19.9.0 output:

(node:140378) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:140378) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, transformSource
(node:140378) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, transformSource
index.test.ts
•   (1 / 1)

  Total:     1
  Passed:    1
  Skipped:   0
  Duration:  0.26ms

Node.js 20.0.0 output:

(node:140181) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:140181) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:140181) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, transformSource
ai commented 1 year ago

@lukeed seems like the issue is between tsm and Node.js in general. Not only uvu. https://github.com/lukeed/tsm/pull/47

Could be related with https://github.com/nodejs/node/pull/44710

vanyauhalin commented 1 year ago

Until it's fixed, you can use tsm via node -r.

$ node -v
v20.0.0
$ cat package.json
{
  "scripts": {
    "test": "node -r tsm index.test.ts"
  },
  "devDependencies": {
    "tsm": "^2.3.0",
    "uvu": "^0.5.6"
  }
}
$ cat index.test.ts
import { test } from 'uvu'; test('one', () => {}); test.run()
$ npm run test

> test
> node -r tsm index.test.ts

•   (1 / 1)

  Total:     1
  Passed:    1
  Skipped:   0
  Duration:  0.36ms
vanyauhalin commented 1 year ago

My previous answer was incorrect. Perhaps, I didn't understand the problem right away. When I used tsm as a loader, I encountered the same error.

$ cat package.json 
{
  "type": "module",
  "scripts": {
    "test": "node --loader tsm index.test.ts"
  },
  "devDependencies": {
    "tsm": "^2.3.0",
    "uvu": "^0.5.6"
  }
}
$ npm run test

> test
> node --loader tsm index.test.ts

(node:19810) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19810) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19810) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, transformSource
ai commented 1 year ago

Fixed in Node.js 20.1.0

lukeed commented 1 year ago

Closing as it appears to have been a Node thing

lukeed commented 1 year ago

Still a Node issue. 🙄 ESM loaders in 20.x lost access to process.argv ... good move /s See https://github.com/nodejs/node/issues/48577

Also reverting #47 for the time being

davidwincent commented 8 months ago

Still seeings problems with node v20.11.1

Component Version
OS Debian GNU/Linux 12 (bookworm)
Node.js v20.11.1
tsm 2.3.0

package.json

{
    "name": "x-x-x-x",
    "version": "0.1.0",
    "description": "",
    "main": "index.js",
    "type": "module",
    "scripts": {
        "dev": "node --require dotenv/config --loader tsm src/index.ts",
        "test": "node --test .",
        "lint": "eslint . --max-warnings 0"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "@kaching-hq/typescript-config": "workspace:^",
        "dotenv": "^16.4.5",
        "tsm": "^2.3.0",
        "typescript": "^5.4.2"
    },
    "dependencies": {
        "firebase-admin": "^12.0.0",
        "googleapis": "^134.0.0"
    }
}

pnpm dev output

> node --require dotenv/config --loader tsm src/index.ts

(node:3856956) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("tsm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)