Property 'makeToken' does not exist (Testing your web app)

Getting Started documentation section “Testing your web app” https://docs.daml.com/getting-started/testing.html#testing-your-web-app when running through the doc I recieve two errors:

Property ‘makeToken’ does not exist on type ‘Authentication’.
Property ‘makeToken’ does not exist on type ‘DamlHub’.

from this code:

const adminLedger = new Ledger({
token: authConfig.makeToken(“participant_admin”),
});

authConfig is referenced to the Config.ts file which has the following code:

export const authConfig: Authentication = (() => {
if (isRunningOnHub()) {
const auth: DamlHub = {
provider: “daml-hub”,
};
return auth;
} else {
const ledgerId: string = process.env.REACT_APP_LEDGER_ID ?? “create-daml-app-sandbox”
const auth: Insecure = {
provider: “none”,
userManagement: userManagement,
makeToken: (loginName) => {
const payload = userManagement.tokenPayload(loginName, ledgerId);
return encode(payload, “secret”, “HS256”);
}
};
return auth;
}
})();

The logic behind the code make sense but I dont understand why the error occurs.

Hi @Elias_Mensah-D ,

To better understand the issue, are you trying to write browser automation tests against a Daml app web UI that is hosted & running on Daml Hub?

I don’t believe it is the Daml Hub - I am just following the Daml “Getting started” documentation since I am new to Daml, the code is run locally. The example provides some code to follow and instructs the reader to make subtle changes https://docs.daml.com/getting-started/testing.html#

Hi @Elias_Mensah-D,

I’ve just followed the getting started guide (daml 2.3.4) and could run the tests with npm test.
Do you mean that you see these errors/problems when you look at the index.test.ts file in VS Code?
I also see these errors in VS Code, but the tests do run with npm test.

Did you complete the getting started docs and finish your first feature? Did that work as expected?
I would like to know the versions you are using, what is the output of each of the following commands:

daml version

node -v

npm version

Having said that, I think that these instructions for “Testing your Web App” are out of date. A lot of tests run by npm test are failing when I follow the instructions.

Hi Raymond

Yes, the errors/problems when looking at the index.test.ts file in VS Code (I should have been more specific) and yes some test do fail. I was concerned that the failures might relate to the errors seen in the VS code.

I completed the first four stages of Getting Started (“Installing the SDK”, “Building your app”, "App Architecture and “Your First Feature” and it did work as expected

Versions
Daml 2.3.4
Node 16.17.0
npm 8.19.1

Are the VS Code errors/problems expected for the index.test.ts?

Hi @Elias_Mensah-D,

Obviously in an ideal world we do not expect code samples in our docs to produce errors, but it does look like some issues have slipped through the cracks in this case. We’re really sorry for that!

We can reproduce the errors you’re mentioning and will try to get the docs fixed in short order.

1 Like

Hi Gary

I’m new to daml, and the “Getting Started” was going so well I assumed I had missed something. This last stage of the “Getting Started” certainly isn’t a show stopper for me and my goal to acquire daml expertise. I appreciate the help from you and your team.

1 Like

Hi @Elias_Mensah-D,

It turns out the file was indeed full of errors — which is a bit surprising as it is definitely run by our CI. My best guess at the moment is that it is being run using a different (probably older) version of the TypeScript compiler, and it simply fails to check a number of things.

We have an updated version of the code sample, but it will take a while for the documentation to get updated. In the meantime, you can see the new version of the file here.

2 Likes

Thank you, @Elias_Mensah-D for posting about this issue. I just had the same experience. Here are some additional notes for anyone that comes after us.

  1. Use the new version of index.test.ts (HT: @Gary_Verhaegen)
  2. I also needed to get the latest version of config.ts
  3. I also needed to use an older version of puppeteer. For example:

npm add --only=dev puppeteer@17.1.3 wait-on @types/jest @types/node @types/puppeteer @types/wait-on

With puppeteer 19.2.0, I was getting this error:

Cannot find module
'puppeteer-core/internal/common/Device.js'
from 'node_modules/puppeteer/lib/cjs/
puppeteer/puppeteer.js'

Your mileage may vary!

image