Express JS in Altassian Forge causing "process.cwd is not a function" error

1.4k Views Asked by At

I am new to development on Jira Cloud and am currently exploring creating apps using the Atlassian Forge. I was trying to use Express JS in the code as a middleware. Turns out that during deployment, it keeps giving this error "process.cwd is not a function."
The error received while deploying the app.

I tried installing process module (via npm i process; which was successfully done) and updating the webpack version but none of it worked.

  1. Can someone please tell what could be causing this error?
  2. If possible please suggest the alternative for using Express JS in Altassian Forge?

Thanks in advance. Apoorva

1

There are 1 best solutions below

0
On

From the documentation:

When a Forge app is invoked, the JavaScript code is executed within the app sandbox. This environment differs from a traditional Node.js environment you might already be familiar with.

You'll need to write your functions in a subset of Node.js. Some globals are not exposed, for example:

  • process (except for process.env)
  • queueMicrotask

which means that some NPM packages that depend on these may not function correctly.

If Express JS depends on process.cwd(), that would explain the error. You may be able to work around this if it depends on it in theory but not in practice:

  • If process.cwd() is only used in test cases or example code, you can delete it or make sure it's not bundled.
  • If it is used, but using a dummy string like "/" would work, you could stub out the call using DefinePlugin or similar.