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

build: switch to node 20, add back loader param #5990

Merged
merged 8 commits into from
Dec 20, 2023
Merged

Conversation

quisquous
Copy link
Owner

@quisquous quisquous commented Dec 7, 2023

Instead of:
ts-node util/sync_files.ts
Now we must do:
node --loader=ts-node/esm util/sync_files.ts

This should work on both node 18 and node 20 (tested locally).

Git workflows were pinned to 18.18.2 via #5991, but are now updated to 20 for constency. It's possible that ts-node will fix this in the future and we can remove (again) the loader param.

Fixes #5910.
Fixes #5989.

Instead of:
  `ts-node util/sync_files.ts`
Now we must do:
  `node --loader=ts-node/esm util/sync_files.ts`

Additionally, as `--loader` is deprecated, an error message
suggests to do in JavaScript, so add a loader script
`--import ./loader.js` to do this work instead

Fixes #5910.
Fixes #5989.
@quisquous quisquous changed the title build: add back loader parameter to node commands build: switch to node 20, add back loader param Dec 7, 2023
@quisquous
Copy link
Owner Author

@xiashtra why the confused emoji?

quisquous added a commit that referenced this pull request Dec 7, 2023
Without #5990, this breaks on 18.19.x and above. See: #5910.
quisquous added a commit that referenced this pull request Dec 7, 2023
Without #5990, this breaks on 18.19.x and above. See: #5910.
github-actions bot pushed a commit that referenced this pull request Dec 7, 2023
github-actions bot pushed a commit that referenced this pull request Dec 7, 2023
@quisquous
Copy link
Owner Author

An alternative to this PR is to switch to using --loader instead of --import which will work on node 18 and node 20. However, every script run will spit out this blob of text about how we should be using --import instead.

$ npm run test

> [email protected] test
> mocha

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

  [▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬..............]

@xiashtra
Copy link
Contributor

xiashtra commented Dec 7, 2023

@xiashtra why the confused emoji?

Nothing you are responsible for. I don't follow Node's development, so I'm just confused why the upstream change. It seems like a lot of tedious boilerplate just to run the utility scripts, and on top of that, if it's considered deprecated, what is the intended long-term solution?

@quisquous
Copy link
Owner Author

quisquous commented Dec 7, 2023

@xiashtra why the confused emoji?

Nothing you are responsible for. I don't follow Node's development, so I'm just confused why the upstream change. It seems like a lot of tedious boilerplate just to run the utility scripts, and on top of that, if it's considered deprecated, what is the intended long-term solution?

My understanding here is that node20 (or really node 18.19.x) introduced a breaking change for loaders: https://nodejs.org/en/blog/announcements/v20-release-announce#custom-esm-loader-hooks-nearing-stable

This broke ts-node, see issue 1997 in https://github.com/TypeStrong/ts-node/issues (not linking directly to avoid more noise on that issue).

So, I think node --loader is deprecated. node --import is the long-term solution (as indicated by the error message I printed above). It's also possible that ts-node gets fixed and we can just run ts-node again in the future.

Edit: other people suggest switching to tsx but tsx uses esbuild, which is probably way faster but also doesn't support quite a few options that our tsconfig.json is using.

@github-actions github-actions bot removed the test label Dec 20, 2023
@quisquous
Copy link
Owner Author

The --loader parameter is deprecated and prints out an error. The way to get around this is to add a file (e.g. ./loader.js) with these contents:

import { register } from 'node:module';
import url from 'node:url';

const __filename = url.fileURLToPath(import.meta.url);
register('ts-node/esm', url.pathToFileURL(__filename));

and then instead of saying node --loader=ts-node/esm util/sync_files.ts you write node --import ./loader.js util/sync_files.ts

However, this doesn't work on node 18, and so we should only switch to it in the future once people stop using node 18.

See: a0679c9

@quisquous quisquous merged commit 4c5cf21 into main Dec 20, 2023
11 checks passed
@quisquous quisquous deleted the loaderparamsiguess branch December 20, 2023 01:27
github-actions bot pushed a commit that referenced this pull request Dec 20, 2023
Instead of:
  `ts-node util/sync_files.ts`
Now we must do:
  `node --loader=ts-node/esm util/sync_files.ts`

This should work on both node 18 and node 20 (tested locally).

Git workflows were pinned to 18.18.2 via #5991, but are now updated to
20 for constency. It's possible that ts-node will fix this in the future
and we can remove (again) the loader param.

Fixes #5910.
Fixes #5989. 4c5cf21
github-actions bot pushed a commit that referenced this pull request Dec 20, 2023
Instead of:
  `ts-node util/sync_files.ts`
Now we must do:
  `node --loader=ts-node/esm util/sync_files.ts`

This should work on both node 18 and node 20 (tested locally).

Git workflows were pinned to 18.18.2 via #5991, but are now updated to
20 for constency. It's possible that ts-node will fix this in the future
and we can remove (again) the loader param.

Fixes #5910.
Fixes #5989. 4c5cf21
github-actions bot pushed a commit to SiliconExarch/cactbot that referenced this pull request Jan 5, 2024
…quous#5990)

Instead of:
  `ts-node util/sync_files.ts`
Now we must do:
  `node --loader=ts-node/esm util/sync_files.ts`

This should work on both node 18 and node 20 (tested locally).

Git workflows were pinned to 18.18.2 via quisquous#5991, but are now updated to
20 for constency. It's possible that ts-node will fix this in the future
and we can remove (again) the loader param.

Fixes quisquous#5910.
Fixes quisquous#5989. 4c5cf21
github-actions bot pushed a commit to SiliconExarch/cactbot that referenced this pull request Jan 6, 2024
…quous#5990)

Instead of:
  `ts-node util/sync_files.ts`
Now we must do:
  `node --loader=ts-node/esm util/sync_files.ts`

This should work on both node 18 and node 20 (tested locally).

Git workflows were pinned to 18.18.2 via quisquous#5991, but are now updated to
20 for constency. It's possible that ts-node will fix this in the future
and we can remove (again) the loader param.

Fixes quisquous#5910.
Fixes quisquous#5989. 4c5cf21
github-actions bot pushed a commit to SiliconExarch/cactbot that referenced this pull request Jan 6, 2024
…quous#5990)

Instead of:
  `ts-node util/sync_files.ts`
Now we must do:
  `node --loader=ts-node/esm util/sync_files.ts`

This should work on both node 18 and node 20 (tested locally).

Git workflows were pinned to 18.18.2 via quisquous#5991, but are now updated to
20 for constency. It's possible that ts-node will fix this in the future
and we can remove (again) the loader param.

Fixes quisquous#5910.
Fixes quisquous#5989. 4c5cf21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NodeJS LTS 20 Support Node 20 requires loader parameter again
2 participants