Node.js 22 compatibility

Forge runtime support for Node.js 22 was announced on 11 December and is recommended according to the documentation.

But the current version (4.1.2) of the @forge/api package still uses the built-in punycode module, which entered the runtime deprecation stage in Node.js 21. This means that every time a function is invoked, the following error is logged:

[DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.

The reason for this warning is that @forge/api uses an old version of node-fetch. One of its dependencies imports the built-in punycode module instead of using the one published on npm (which has the same name and is not deprecated):

@forge/api@4.1.2
  └─┬ node-fetch@2.7.0
    └─┬ whatwg-url@5.0.0
      └── tr46@0.0.3 <- This one uses `punycode`

The deprecation doesn’t affect the functionality of apps, but it produces a lot of unnecessary log lines.

15 Likes

I saw that as well and reverted back to v20.

Also the CLI doesn’t seem to support Node 22 either, only 18 and 20 see https://developer.atlassian.com/platform/forge/getting-started/#before-you-begin

5 Likes

Also discussed here: Forge CLI does not support latest Node.js LTS version - #5 by SimonCordes

The rollout of the runtime support is disappointing.

I have to rollback switching to Node 22 from our dev branch because of these two issues (punycode and @forge/cli). Note that all Forge documents appear to be encouraging node22 despite these issues.

3 Likes

Hi all, thank you for providing feedback. Firstly, I’d like to apologise about your experience, I have made a note of all of your points.

Just to give you all an update on some of the issues that you’ve noticed:

  • Regarding the use of v2 of node-fetch (which has a dependency on deprecated punycode) we have plans to remove this dependency all together from @forge/api in preference of global fetch, which is available from Node.js 18 onwards (ticket). This is on our team’s backlog for this quarter.
  • Regarding CLI support, the CLI should work with Node.js 22 out of the box, we will need to update a couple of things (that warning and the fact that the CLI has a dependency on node-fetch as well). I have created a ticket for this and have shared it with the relevant team.
  • I also want to point out that the CLI is independent of the Forge runtime, so you can use different Node.js versions between the two. At the same time, I understand that you probably want to be running the same version of Node.js locally so you can test your app locally running the same version under Forge tunnel.
3 Likes

So is the bottom line here that we should be using nodejs20.x instead of nodejs22.x in production pushes until this is resolved?

Hi guys, has this been resolved yet?

Hi, please follow this ticket for updates regarding the removal of node-fetch from @forge/api.

In terms of adopting the Node.js 22 runtime, as far as I know this is a deprecation warning so should not affect the functionality of your app so you may use it. If you wish to stay on Node.js 20 runtime until we rollout an update for the @forge/api package, that’s totally valid as well.

2 Likes

Hi all, sorry for the delay. I just wanted to give you all a heads up that we have resolved the two issues that was preventing the uptake of the Node.js 22 runtime.

  • Forge CLI version 11.1.0 and later should now fully support Node.js 22
  • @forge/api version 5.1.0 no longer has a dependency on the node-fetch library (this was also requested here).
7 Likes

Hi @BoZhang

We are still seeing this error in the Forge console logs:
(node:8) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)

When we run “npm ls punycode” the only dependency we see is on eslint which is a dev dependency. We are on v5.1.1 for @forge/api. Thoughts?

Hi @GirishReddy, hmm that’s interesting, the latest published version of @forge/api shouldn’t have a dependency on eslint. Is there any chance that your application has a dependency on eslint or could it be coming from another package? Are you able to post the output you get from npm ls punycode?

Here’s the output. Yes, our application has a dependency on eslint but it’s only a devDependency so I was wondering why I am seeing the error in Forge runtime logs/

work@1.0.12 /forge
└─┬ eslint@7.32.0
└─┬ ajv@6.12.6
└─┬ uri-js@4.4.1
└── punycode@2.3.1

1 Like

Hi @BoZhang ,
I have same error. My output like this:
jira-admin-page-ui-kit@1.1.9
└─┬ eslint@8.56.0
└─┬ ajv@6.12.6
└─┬ uri-js@4.4.1
└── punycode@2.1.1

My node version is v22.11.0 and my package.json is below:

{
  "name": "jira-admin-page-ui-kit",
  "version": "1.1.9",
  "main": "index.js",
  "license": "MIT",
  "private": true,
  "scripts": {
    "lint": "eslint src/**/*"
  },
  "devDependencies": {
    "eslint": "^8.56.0",
    "eslint-plugin-react-hooks": "^4.6.0"
  },
  "dependencies": {
    "@forge/api": "^5.1.1",
    "@forge/bridge": "4.5.0",
    "@forge/events": "^1.0.0",
    "@forge/react": "11.1.0",
    "@forge/resolver": "1.6.9",
    "react": "^18.2.0"
  }
}

Hi, I took a closer look with the –trace-deprecation option turned on and the issue seems to stem from the the Forge CLI which still depends on version 2 of node-fetch, which has a dependency on punycode.
I was under the impression that we had removed the dependency, but it seems not.
I have raised a bug on our end to track this.

I do want to point out that this only affects local development and will not affect your apps running in Forge functions, so please feel free to utilise the Node.js 22 runtime for your Forge functions if you are in a position to do so.

I am sorry about the inconvenience.

4 Likes