haxiomic / dts2hx

Converts TypeScript definition files (d.ts) to haxe externs (.hx) via the TypeScript compiler API
MIT License
131 stars 8 forks source link

Errors building and running express example #123

Open theJenix opened 1 year ago

theJenix commented 1 year ago

Following the instructions to try and get the express example to run. When I run npm install, it runs dts2hx but produces a ton of errors like:

> Error: [TypeScript 3.7] Type 'Response' is not generic. (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/@types/express-serve-static-core/index.d.ts:68:14)
> Error: [TypeScript 3.7] Type 'Request' is not generic. (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/@types/express-serve-static-core/index.d.ts:81:10)
> Error: [TypeScript 3.7] Type 'Response' is not generic. (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/@types/express-serve-static-core/index.d.ts:82:10)
...
> Error: [TypeScript 3.7] ';' expected. (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/@types/express-serve-static-core/index.d.ts:363:84)
> Error: [TypeScript 3.7] ';' expected. (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/@types/express-serve-static-core/index.d.ts:378:13)
...

when trying to convert the modules express-serve-static-core and mime.

If I ignore those errors and attempt to build Server.hx via haxe build.hxml I get the following error: Server.hx:17: characters 31-36 : Class<express.Router> has no field call_ (Suggestion: call)

When I change call_ to call on that line, it builds. I can then run the server and see the Hello World page, but when I click on the /birds link I see:

    at Layer.handle [as handle_request] (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/index.js:328:13)
    at /Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/index.js:346:12)
    at next (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/index.js:280:10)
    at expressInit (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/middleware/init.js:40:5)
    at Layer.handle [as handle_request] (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/index.js:328:13)
    at /Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/Users/jesse/Development/src/bommer.io/addins/specs/scratch/dts2hx/examples/express/node_modules/express/lib/router/index.js:346:12)
SproutingSprouter commented 1 year ago

Ran into the same issue. Found there are two fixes necessary to make it work:

As you mentioned, line 17 of the example needs to be changed to this: var router = express.Router.call();

And then on line 35, take out the '.call': app.use('/birds', router);

After making these changes the express example worked and I was able to browse to the /birds and the /birds/about routes.

neimanpinchas commented 4 months ago

New issue node/Events.hx:16: characters 24-30 : Not enough type parameters for node.Events

neimanpinchas commented 4 months ago

At end I solved this by replacing the events definition with an empty dummy class

since I am not using it directly, but the request module does at runtime, I am OK with that