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

Documented way to include ts-node with esm prints warning, alternative swallows errors #2359

Closed
timvahlbrock opened this issue Dec 17, 2023 · 2 comments · Fixed by #2363
Closed
Assignees
Labels
🐛 bug Defect / Bug ✅ accepted The core team has agreed that it is a good idea to fix this

Comments

@timvahlbrock
Copy link

👓 What did you see?

The documented way of registering ts-node in esm context by setting the nom script to cross-env NODE_OPTIONS='--loader ts-node/esm' cucumber-js creates the following warning.

(node:77515) 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("ts-node/esm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)

I simplified that to adding this to my cucumber.mjs:

import { register } from "node:module";
import { pathToFileURL } from "node:url";
register("ts-node/esm", pathToFileURL("./"));

This works, but typescript errors are swallowed (by VError in cucumber), because they are not actual error instances:

./node_modules/verror/lib/verror.js:298
        mod_assertplus.ok(mod_isError(err), 'err must be an Error');
                ^
AssertionError [ERR_ASSERTION]: err must be an Error
    at Function.VError.fullStack (./node_modules/verror/lib/verror.js:298:17)
    at Object.run [as default] (./node_modules/@cucumber/cucumber/src/cli/run.ts:35:35) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

✅ What did you expect to see?

No warnings, TS Error is printed.

📦 Which tool/library version are you using?

@cucumber/cucumber: 10.0.1
ts-node: 10.9.2
Node: 20

🔬 How could we reproduce it?

Clone https://github.com/timvahlbrock/cucumber-tsnode, install dependencies, run scripts test and test-old. The earlier shows the V-Error problem, the later the Node Warning.

📚 Any additional context?


This text was originally generated from a template, then edited by hand. You can modify the template here.

@davidjgoss davidjgoss added 🐛 bug Defect / Bug ✅ accepted The core team has agreed that it is a good idea to fix this labels Dec 21, 2023
@davidjgoss davidjgoss self-assigned this Dec 21, 2023
@davidjgoss
Copy link
Contributor

Thanks for raising @timvahlbrock.

I've got a PR up to remove verror since we can now use platform-native stuff to achieve the same thing. This would make it tolerant of errors that aren't Error instances, so should solve that problem for you.

For the point about loaders, I've raised #2364. Both --loader and register() are still experimental, we may let this shake out a bit before committing to putting something in our own API, just to manage expectations.

@davidjgoss
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug ✅ accepted The core team has agreed that it is a good idea to fix this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants