colyseus / decentraland

Colyseus + Decentraland demonstration
https://play.decentraland.org/?position=25%2C23
MIT License
14 stars 6 forks source link

"dcl deploy" not work #2

Open RaidelRoss opened 2 years ago

RaidelRoss commented 2 years ago

I am cloning your example and "dcl deploy" does not work, problems importing libraries

endel commented 2 years ago

Hi @RaidelRoss, what are the problems you're having?

RaidelRoss commented 2 years ago

Hello I have tried to add your excellent Colyseus to my Decentraland project i'll go step by step

1) Create a default Decentraland project "Cube spawner" dcl init

2) Verify that the project works correctly dcl start

3) Verify that the "deploy" does not throw errors dcl deploy

4) Install colyseus.js npm install --save colyseus.js

5) Add colyseus.js to the "bundleDependencies" in the package.json

"bundleDependencies": [
    "colyseus.js"
  ]

6) Include a few ///<reference to your source-code

{
  "compilerOptions": {
    // ...
    "noLib": false,
    // ...
  }
}

7) Add in the game.js scene the following code at the beginning

///<reference lib="es2015.symbol" />
///<reference lib="es2015.symbol.wellknown" />
///<reference lib="es2015.collection" />
///<reference lib="es2015.iterable" />

import { Client } from "colyseus.js";

8) Start the project dcl start

And throw these errors even though the project works

Error C:/Users/Familia/Downloads/Proy/node_modules/typescript/lib/lib.es2015.iterable.d.ts (227,59): Cannot find name 'Awaited'.
  Error C:/Users/Familia/Downloads/Proy/node_modules/typescript/lib/lib.es2015.iterable.d.ts (235,60): Cannot find name 'Awaited'.

9) But the deployment doesn't work dcl deploy

image


Sample code posted here https://github.com/RaidelRoss/decentraland_colyseus_test

thank you very much for your help

endel commented 2 years ago

Oh, I see, thanks @RaidelRoss, we've been in chats with the Decentraland team about this, here's the findings we've had, and a proposed workaround. Let me know if you have any questions!


I noticed that the decentraland-ecs package includes a full copy of the es5.d.ts file from TypeScript (perhaps with some modifications?). The cause of this problem is because a more recent version of TypeScript has added Awaited on their base es5.d.ts file.

A quick workaround for this would be to include the Awaited type on the project itself (see sources below), but ideally the es5.d.ts shipped within Decentraland should include it, too:

declare global {

/**
 * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`.
 */
type Awaited<T> =
    T extends null | undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` mode
        T extends object & { then(onfulfilled: infer F): any } ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
            F extends ((value: infer V, ...args: any) => any) ? // if the argument to `then` is callable, extracts the first argument
                Awaited<V> : // recursively unwrap the value
                never : // the argument to `then` was not callable
        T; // non-object or non-thenable

}

You can see the Awaited type on their es5.d.ts file here: https://github.com/microsoft/TypeScript/blob/1071240907ab7aae63ecc9c0bbde42aa51dc7669/src/lib/es5.d.ts#L1498-L1507

RaidelRoss commented 2 years ago

Wonderful!! it works perfectly!

here the project with the solution for other developers. https://github.com/RaidelRoss/decentraland_colyseus_test

thanks again :)

MetaverseUnknower commented 1 year ago

The steps in here have worked for me so far, but I'm getting this error when trying to build an SDK 6 scene that uses another library that's using Colyseus.

processing <my dir>/dcl-sdk6/src/game.ts
  Error <my dir>/dcl-sdk6/node_modules/@colyseus/schema/lib/types/HelperTypes.d.ts (13,11): Type 'S' is not assignable to type 'string'.
  Type 'Key' is not assignable to type 'string'.
    Type 'number' is not assignable to type 'string'.
endel commented 1 year ago

Hi @MetaverseUnknower, does adding skipLibCheck to tsconfig help?

{
  "compilerOptions": {
    // ...
    "skipLibCheck": true,
    // ...
  }
}

This TypeScript error is due to Colyseus relying on modern features of the language. AFAIK Decentraland ships with a fixed version of TypeScript and may not be possible to upgrade the version, although would be recommended to always use latest.

MetaverseUnknower commented 1 year ago

That did the trick! Thank you @endel for the lightning-fast response on this, and for all the work you've done with Colyseus.