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

Upgrade tsx to v4.x and use it directly to fix issue with Node v18.19 #9653

Merged
merged 6 commits into from
Dec 8, 2023

Conversation

Tobbe
Copy link
Member

@Tobbe Tobbe commented Dec 8, 2023

We saw some issues with our unit tests on Node v18.19. See links below more info

nodejs/node#51048
https://github.com/privatenumber/tsx/releases/tag/v4.1.2

Dom worked around this by pinning Node to 18.18. This PR un-pinns Node, to get v18.19. After clearing the GitHub cache (twice) I was able to reproduce the issue in this PR on CI. https://github.com/redwoodjs/redwood/actions/runs/7139459915/job/19446057016?pr=9653

# /home/runner/work/redwood/redwood/packages/eslint-plugin/src/__tests__/service-type-annotations.test.ts:1
# import { describe, it } from 'node:test'
# ^^^^^^
# SyntaxError: Cannot use import statement outside a module
#     at internalCompileFunction (node:internal/vm:73:18)
#     at wrapSafe (node:internal/modules/cjs/loader:1274:20)
#     at Module._compile (node:internal/modules/cjs/loader:1320:27)
#     at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
#     at Module.load (node:internal/modules/cjs/loader:1197:32)
#     at Module._load (node:internal/modules/cjs/loader:1013:12)
#     at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:202:29)
#     at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
#     at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
#     at async loadESM (node:internal/process/esm_loader:34:7)
# Node.js v18.19.0
# Subtest: /home/runner/work/redwood/redwood/packages/eslint-plugin/src/__tests__/service-type-annotations.test.ts
not ok 2 - /home/runner/work/redwood/redwood/packages/eslint-plugin/src/__tests__/service-type-annotations.test.ts
  ---
  duration_ms: 183.717365
  location: '/home/runner/work/redwood/redwood/packages/eslint-plugin/src/__tests__/service-type-annotations.test.ts:1:1'
  failureType: 'testCodeFailure'
  exitCode: 1
  error: 'test failed'
  code: 'ERR_TEST_FAILURE'

Then, upgrading tsx to latest version (v4.1.3) we get this error message instead

# node:internal/process/esm_loader:40
#       internalBinding('errors').triggerUncaughtException(
#                                 ^
# Error: tsx must be loaded with --import instead of --loader
# The --loader flag was deprecated in Node v20.6.0 and v18.19.0
#     at z (file:///home/runner/work/redwood/redwood/node_modules/tsx/dist/esm/index.mjs:1:1800)
#     at Hooks.addCustomLoader (node:internal/modules/esm/hooks:202:24)
#     at Hooks.register (node:internal/modules/esm/hooks:168:16)
#     at async initializeHooks (node:internal/modules/esm/utils:167:5)
#     at async customizedModuleWorker (node:internal/modules/esm/worker:104:24)
# Node.js v18.19.0
# Subtest: /home/runner/work/redwood/redwood/packages/eslint-plugin/src/__tests__/unsupported-route-components.test.ts

So, the final fix was to just use tsx directly, letting it act like a wrapper around node, instead of providing it as a loader. Which is the recommended way to use tsx anyway.
From it's README:

Usage

tsx is a Node.js wrapper

tsx wraps around Node.js to enhance it with TypeScript support. Because it's a drop-in replacement for node, it supports all Node.js command-line flags.

# --no-warnings is a Node.js flag
tsx --no-warnings ./file.ts

@Tobbe Tobbe changed the title Allow latest node 18 (v18.19.x), to see tests failing Upgrade tsx to v4.x to fix issue with Node v18.19 Dec 8, 2023
@Tobbe Tobbe added the release:chore This PR is a chore (means nothing for users) label Dec 8, 2023
@Tobbe Tobbe added this to the chore milestone Dec 8, 2023
@Tobbe Tobbe changed the title Upgrade tsx to v4.x to fix issue with Node v18.19 Try to trigger issue with Node v18.19 Dec 8, 2023
@Tobbe Tobbe changed the title Try to trigger issue with Node v18.19 Upgrade tsx to v4.x to fix issue with Node v18.19 Dec 8, 2023
@Tobbe Tobbe changed the title Upgrade tsx to v4.x to fix issue with Node v18.19 Upgrade tsx to v4.x and use it directly to fix issue with Node v18.19 Dec 8, 2023
@Tobbe Tobbe enabled auto-merge (squash) December 8, 2023 12:51
@Tobbe Tobbe merged commit bc5e7f2 into redwoodjs:main Dec 8, 2023
32 checks passed
@Tobbe Tobbe deleted the tobbe-node-18-tsx-4 branch December 8, 2023 18:13
@Josh-Walker-GM Josh-Walker-GM modified the milestones: chore, v8.0.0 Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:chore This PR is a chore (means nothing for users)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants