Property 'getTasks' does not exist on type 'Tasks'. Did you mean 'getTask'?ts(2551) index.d.ts(2060, 13): 'getTask' is declared here.

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 (Asana) 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??

I use these below:

  1. Next.js
  2. React
  3. JavaScript
  4. Node.js

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

// node-asana/tasks.js at 6bf00fb3257847744bf0ebe2dc0e95c445477282 · Asana/node-asana · GitHub
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