How to replace AJS.Meta by require("jira/util/data/meta")

Hi,

My Jira app needs to be compatible with different versions of Jira.
So I need to get the current version of Jira in order to known which request I can make via the REST API.

I found two solutions : call AJS.Meta.get(‘version-number’) or JIRA.Version.isGreaterThanOrEqualTo().

Both work but I have similar warnings.

For AJS.Meta:

The global object AJS.Meta is deprecated. Please use require([“jira/util/data/meta”]) instead.

So in my code, I replaced

const jiraVersion = AJS.Meta.get('version-number')

by

const meta = require("jira/util/data/meta");
const jiraVersion = meta.get('version-number').

but I get the error message

Can’t resolve ‘jira/util/data/meta’ in…

What am I missing?

Thanks!

:wave:
Unfortunately, the require() method on the client-side works differently from the CommonJS require statement. When executed in the browser it is an async operation and it takes a callback function that will return the object you are fetching. Which means that to use it in this code example, you will have to write:

require(["jira/util/data/meta"], function(meta) {
  const jiraVersion = meta.get('version-number').
});

You can read more about the require method in the Jira front-end here: Jira Front-end API

1 Like

@remie Thanks for your help!

I tried your piece of code but I still got the same error.

Finally I found the cause of the problem: I use webpack to bundle my app.
So require() was translated by webpack.

The following code works:

__non_webpack_require__(["jira/util/data/meta"], function(meta) {
  const jiraVersion = meta.get('version-number').
});

or

window.require(["jira/util/data/meta"], function(meta) {
  const jiraVersion = meta.get('version-number').
});
1 Like