Code is here, probably not complex. This code is just hitting the API to get the tasks of a certain worker in a certain workspace in Asana.
import asana from "asana";
const GetAsanaData = () => {
const personalAccessToken = `Bearer 1/1200...`;
const workspace = "1200...";
const assignee = "12007...";
const opt_fields = ["name", "completed", "completed_at"];
const client = asana.Client.create().useAccessToken(personalAccessToken);
const result = client.tasks
.getTasks({
workspace: workspace,
assignee: assignee,
opt_fields: opt_fields,
})
.then((response) => response);
return result;
};
export default GetAsanaData;
First error says;
Could not find a declaration file for module âasanaâ. âC:/Users/81906/Documents/polygon-hr/node_modules/asana/index.jsâ implicitly has an âanyâ type. Try npm i --save-dev @types/asana
if it exists or add a new declaration (.d.ts) file containing declare module 'asana';
ts(7016)
Then I followed this error and typed npm i --save-dev @types/asana
in my vscode terminal, then second error happens and says;
Property âgetTasksâ does not exist on type âTasksâ. Did you mean âgetTaskâ?ts(2551) index.d.ts(2060, 13): âgetTaskâ is declared here.
Indeed, if I looked at the referenced index.d.ts(2060, 13), there are no getTasks instead of getTask. However, the official documentation (Get multiple tasks) says to call it this way⊠Is it a bug in the library? In other words, should I give up using this library and seek for another way to do this??
Be careful with one thing: the API endpoint naming could be inconsistent with the actual method names within the library.
Surprisingly enough, I work with the nodeJS lib and did not have to import the typing. Whatâs the content of the referred index.d.ts?
i.e. like this below;
VSCode and Typescript asked me you meant this getTask instead of getTasks because getTasks is not included in this file âindex.d.tsâ
I confirmed it by pressing âctrl + fâ in the file.
// https://github.com/Asana/node-asana/blob/6bf00fb3257847744bf0ebe2dc0e95c445477282/lib/resources/gen/tasks.js#L245-L262
/**
* Get a task
* @param {String} taskGid: (required) The task to operate on.
* @param {Object} params: Parameters for the request
* - optFields {[String]}: Defines fields to return. Some requests return *compact* representations of objects in order to conserve resources and complete the request more
* efficiently. Other times requests return more information than you may need. This option allows you to list the exact set of fields that the API should be sure to return for
* the objects. The field names should be provided as paths, described below. The id of included objects will always be returned, regardless of the field options.
* - optPretty {Boolean}: Provides âprettyâ output. Provides the response in a âprettyâ format. In the case of JSON this means doing proper line breaking and indentation to
* make it readable. This will take extra time and increase the response size so it is advisable only to use this during debugging.
* @param {Object} [dispatchOptions]: Options, if any, to pass the dispatcher for the request
* @return {Promise} The requested resource
*/
getTask(taskGid: string, params?: any, dispatchOptions?: any): Promise<Tasks.Type>;
And one thing I found is that if I replace below, the original error has disappeared but new error happened. I tried to replace like below because your official document says that it use ârequireâ instead of âimportâ.
// before
import asana from "asana";
â
// after
const asana = require("asana");
Then this new error happened as below.
Failed to compile
./node_modules/readline/readline.js:1:0
Module not found: Can't resolve 'fs'
Import trace for requested module:
./node_modules\asana\lib\auth\native_flow.js
./node_modules\asana\lib\auth\index.js
./node_modules\asana\index.js
./services\asanaService.tsx
./components\RadarChart.tsx
./pages\index.tsx
https://nextjs.org/docs/messages/module-not-found
Converting import
to require
itself was correct?? If so, should I struggle with this new error âModule not found: Canât resolve âfsââ?
Thank you for your advise below:
Be careful with one thing: the API endpoint naming could be inconsistent with the actual method names within the library.
As you say, I tried to search another method like below in âindex.d.tsâ, but there is no match neither.
- getTasksForUserTaskList
- getTasksForProject
// https://github.com/Asana/node-asana/blob/6bf00fb3257847744bf0ebe2dc0e95c445477282/lib/resources/gen/tasks.js#L245-L262
Thatâs weird because I looked at that file on my end and just below getTask
I actually have a getTasks
. Donât you?
Module not found: Can't resolve 'fs'
Are you using the nodeJS library to work in client side Javascript? Or are you doing actual server side code?
Youâre right.
getTasks method is in here.
node_modules > asana > lib > resource > gen > tasks.js
When I used import
, then typescript tried to look into this directory.
node_modules > @types > asana > index.d.ts > { } asana > { } resources > Tasks
Then it said there is no getTasks, but as I said, when I switched import
to require
, as official document says, this error has gone successfully.
So, maybe this error itself is resolved!!
That means the last problem is that Module not found: Can't resolve 'fs'
.
The error Module not found: Can't resolve 'fs'
is caused, I think, by my poor understanding when and where this library/api is run at server side or client side.
I might have to use this library/api in getServerSideProps function in Next.js to use this library/api in server side because this library/api includes nodeJS library. Am I right??
In Next.js, thanks to this framework, it is a little bit vague for me that if I call this asana library in server side or client sideâŠ
I can talk confidently about my own use. The NodeJS library is meant to be used server side. When use on the server, it knows âfsâ (which is a library to access the file system). A long time ago (years ago) I mentioned this bug to the dev team, explaining that you canât use their library for client code.
My workaround since then: I made a copy of the index file, removed the mention of âfsâ, and I have a script to overide the node_modules index file with mine every time I update the modules.
This is completely dirty but has been working for years.
Oh I found my post look Node library requires lib unavailable for a web use - #4 by Ross_Grambo
Thank you for your patience with me. Should I ask you to close this topic and continue the conversation in the topic you guided me to?
If this is exactly the same issue yes for sure!
Ok, thank you for your advise.
For further communication, Iâll wait for your reply in the topic of the link you guided me to.
1 Like