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 Node.js to v20 and fix loading swc-node #4513

Merged
merged 36 commits into from
Feb 19, 2024
Merged

Conversation

acwhite211
Copy link
Member

Fixes #4458

This PR temporarily migrates away from swc until the issues swc-project/swc-node#748 and swc-project/swc-node#743 are in the next release, presumably version 1.8.1. This fix will be considered as a solution when the Weblate error doesn't occur in our project build/testing.

@acwhite211 acwhite211 added the 1 - Bug Incorrect behavior of the product label Feb 9, 2024
@acwhite211 acwhite211 added this to the 7.9.4 milestone Feb 9, 2024
@acwhite211 acwhite211 self-assigned this Feb 9, 2024
@acwhite211 acwhite211 changed the title migrate for swc to tsx until swc-node repo is fixed Migrate from swc to tsx until swc-node repo is fixed Feb 9, 2024
@acwhite211 acwhite211 changed the title Migrate from swc to tsx until swc-node repo is fixed Migrate away from swc until swc-node repo is fixed Feb 9, 2024
@ehaynes99
Copy link

Not associated with this project, just saw the link in swc-project/swc-node#748

This was already fixed, so you should be able to replace the `--loader like:

@@ -16,16 +16,16 @@
   },
   "scripts": {
     "//": "All of these should be executed from the js_src directory",
-    "localizationTests": "node --loader @swc-node/register/esm lib/localization/__tests__/scanUsages.ts",
-    "pullFromWeblate": "node --loader @swc-node/register/esm lib/localization/utils/pull.ts",
-    "schema:extract": "node --loader @swc-node/register/esm lib/localization/schema-localization/extract.ts",
-    "schema:pullFromWeblate": "node --loader @swc-node/register/esm lib/localization/schema-localization/pull.ts",
+    "localizationTests": "node --import @swc-node/register/esm-register lib/localization/__tests__/scanUsages.ts",
+    "pullFromWeblate": "node --import @swc-node/register/esm-register lib/localization/utils/pull.ts",
+    "schema:extract": "node --import @swc-node/register/esm-register lib/localization/schema-localization/extract.ts",
+    "schema:pullFromWeblate": "node --import @swc-node/register/esm-register lib/localization/schema-localization/pull.ts",
     "test": "npm run typecheck && npm run unitTests && npm run localizationTests",
     "typecheck": "tsc",
     "unitTests": "jest",
     "unitTests:coverage": "jest --coverage",
     "unitTests:watch": "jest --watch",
-    "validateWeblate": "node --loader @swc-node/register/esm lib/localization/__tests__/validateWeblate.ts"
+    "validateWeblate": "node --import @swc-node/register/esm-register lib/localization/__tests__/validateWeblate.ts"
   },
   "dependencies": {
     "@codemirror/lang-json": "^6.0.0",

@maxpatiiuk
Copy link
Member

@ehaynes99 Thanks for the comment!
@acwhite211 can you try out that solution?

we moved from ts-node to swc because ts-node started failing on new node.js version. Now swc is failing on new node.js version 🤪

@acwhite211
Copy link
Member Author

Looks like because we are currently using node version 18.19.0 that we should be using --loader instead of --import as it says in the README.

@realVinayak realVinayak removed their request for review February 13, 2024 00:38
@maxpatiiuk
Copy link
Member

Can we update the CI and Dockerfile to 20 then?
According to https://nodejs.org/en/about/previous-releases, Node.js 18 is currently in maintenance mode

@acwhite211
Copy link
Member Author

acwhite211 commented Feb 14, 2024

After updating to node v20.6 and changing --loader @swc-node/register/esm to --import @swc-node/register/esm-register in the package.json, there still is an error I'm working on resolving

> node --import @swc-node/register/esm-register lib/localization/__tests__/scanUsages.ts --emit ../../../weblate-localization/strings
node:internal/modules/esm/resolve:303
  return new ERR_PACKAGE_PATH_NOT_EXPORTED(
         ^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './esm-register' is not defined by "exports" in /home/runner/work/specify7/specify7/specifyweb/frontend/js_src/node_modules/@swc-node/register/package.json imported from /home/runner/work/specify7/specify7/specifyweb/frontend/js_src/
    at exportsNotFound (node:internal/modules/esm/resolve:303:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:650:9)
    at packageResolve (node:internal/modules/esm/resolve:836:14)
    at moduleResolve (node:internal/modules/esm/resolve:910:20)
    at defaultResolve (node:internal/modules/esm/resolve:1130:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:328:34)
    at loadESM (node:internal/process/esm_loader:23:33) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Node.js v20.11.0
Error: Process completed with exit code 1.

I get this error when I try using esm instead of esm-register

> node --import @swc-node/register/esm lib/localization/__tests__/scanUsages.ts --emit ../../../weblate-localization/strings
node:internal/modules/esm/get_format:160
  throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
        ^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/runner/work/specify7/specify7/specifyweb/frontend/js_src/lib/localization/__tests__/scanUsages.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
    at async link (node:internal/modules/esm/module_job:76:21) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Node.js v20.11.0
Error: Process completed with exit code 1.

@acwhite211
Copy link
Member Author

ok, so node got upgraded to >v20.6, so the directions are to use node --import @swc-node/register/esm-register lib/localization/__tests__/scanUsages.ts but it still seems to only work with using node --loader @swc-node/register/esm lib/localization/__tests__/scanUsages.ts

Copy link
Member

@maxpatiiuk maxpatiiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given how many commits this took, I am sorry you had to fight with it so much to get it to work
but thanks for updating us to newer node.js version

specifyweb/frontend/js_src/package.json Outdated Show resolved Hide resolved
@maxpatiiuk
Copy link
Member

@acwhite211 acwhite211 changed the title Migrate away from swc until swc-node repo is fixed Upgrade Node.js to v20 and fix loading swc-node Feb 15, 2024
@acwhite211
Copy link
Member Author

This PR is looking good now. Should be ready to merge into production.

Copy link
Member

@maxpatiiuk maxpatiiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💎

README.md Show resolved Hide resolved
@acwhite211 acwhite211 merged commit 7041601 into production Feb 19, 2024
9 checks passed
@acwhite211 acwhite211 deleted the issue-4458 branch February 19, 2024 16:16
@maxpatiiuk
Copy link
Member

Hmm, the github action is still failing despite the changes in this PR:

Screenshot 2024-02-19 at 10 59 30

ok, so node got upgraded to >v20.6, so the directions are to use node --import @swc-node/register/esm-register lib/localization/tests/scanUsages.ts but it still seems to only work with using node --loader @swc-node/register/esm lib/localization/tests/scanUsages.ts

That is because our local version of @swc-node/register is outdated.
The new feature is only available in the newer version - https://github.com/swc-project/swc-node/releases/tag/%40swc-node%2Fregister%401.8.0#:~:text=feat%3A%20add%20esm%2Dregister%20for%20node%3E20.6%20by%20%40yeliex%20in%20%23748

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - Bug Incorrect behavior of the product
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Weblate tests fails in production after xml-editor merge
5 participants