Uwazi: Running $ yarn hot gives several type errors

Created on 15 May 2020  路  19Comments  路  Source: huridocs/uwazi

On current DEV, if you run $ yarn hot, and wait for the build to finish the webpack and wait a few seconds, you get outputs like this:

app/api/auth2fa/routes.ts:24:5 - error TS2345: Argument of type '(req: Request<ParamsDictionary>, res: Response, next: NextFunction) => void | Response' is not assignable to parameter of type 'Middleware'.
  Types of parameters 'req' and 'req' are incompatible.
    Type '{ user: User; body: any; }' is missing the following properties from type 'Request<ParamsDictionary>': get, header, accepts, acceptsCharsets, and 76 more.

24     needsAuthorization(['admin', 'editor']),
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app/api/auth2fa/routes.ts:26:12 - error TS7006: Parameter 'req' implicitly has an 'any' type.

26     async (req, res, next) => {
              ~~~

app/api/auth2fa/routes.ts:26:17 - error TS7006: Parameter 'res' implicitly has an 'any' type.

26     async (req, res, next) => {
                   ~~~

app/api/auth2fa/routes.ts:26:22 - error TS7006: Parameter 'next' implicitly has an 'any' type.

26     async (req, res, next) => {
                        ~~~~

app/api/auth2fa/routes.ts:38:5 - error TS2345: Argument of type '(req: Request<ParamsDictionary>, res: Response, next: NextFunction) => void | Response' is not assignable to parameter of type 'Middleware'.

38     needsAuthorization(['admin', 'editor']),
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app/api/auth2fa/routes.ts:44:12 - error TS7006: Parameter 'req' implicitly has an 'any' type.

44     async (req, res, next) => {
              ~~~

app/api/auth2fa/routes.ts:44:17 - error TS7006: Parameter 'res' implicitly has an 'any' type.

44     async (req, res, next) => {
                   ~~~

app/api/auth2fa/routes.ts:44:22 - error TS7006: Parameter 'next' implicitly has an 'any' type.

44     async (req, res, next) => {
                        ~~~~

app/api/auth2fa/routes.ts:56:5 - error TS2345: Argument of type '(req: Request<ParamsDictionary>, res: Response, next: NextFunction) => void | Response' is not assignable to parameter of type 'Middleware'.

56     needsAuthorization(['admin']),
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app/api/auth2fa/routes.ts:67:12 - error TS7006: Parameter 'req' implicitly has an 'any' type.

67     async (req, res, next) => {
              ~~~

app/api/auth2fa/routes.ts:67:17 - error TS7006: Parameter 'res' implicitly has an 'any' type.

67     async (req, res, next) => {
                   ~~~

app/api/auth2fa/routes.ts:67:22 - error TS7006: Parameter 'next' implicitly has an 'any' type.

67     async (req, res, next) => {
                        ~~~~

@daneryl, @konzz or @fnocetti , you are using macOS, can you please confirm this is happening on your end to?

Bug High Sprint

All 19 comments

It's happening on my end. It's strange that I didn't see these errors when working in the csv export improvements branch, but it must be related to the new global type definitions for express. This file has an old implementation of the definitions that may be complaining.
I can take a look.

Thank you @fnocetti . I'm removing @daneryl for the time being. Let us know what you find.

Actually, looks like @konzz already took care of this in his PR https://github.com/huridocs/uwazi/pull/2828
May be we should wait for it to be merged to avoid conflicts?
Anyways, I'll check it is not happening in his branch and let you know.

No. That branch is giving another set of conflicts, more or less of the same nature:

app/api/socketio/middleware.ts:1:20 - error TS7016: Could not find a declaration file for module 'cookie'. '/home/rafapolit/workspace/uwazi/node_modules/cookie/index.js' implicitly has an 'any' type.
  Try `npm install @types/cookie` if it exists or add a new declaration (.d.ts) file containing `declare module 'cookie';`

1 import cookie from 'cookie';
                     ~~~~~~~~

app/api/socketio/middleware.ts:2:60 - error TS7016: Could not find a declaration file for module 'socket.io'. '/home/rafapolit/workspace/uwazi/node_modules/socket.io/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/socket.io` if it exists or add a new declaration (.d.ts) file containing `declare module 'socket.io';`

2 import socketIo, { Server as SocketIoServer, Socket } from 'socket.io';
                                                             ~~~~~~~~~~~

Maybe it's not the same, actually.

Yeah, they're different errors. Those for dev were injected by me (I'm sorry), but effectively konz took care of them.

For the ones on his branch, we should need to install the involved types...

@RafaPolit @fnocetti we should include yarn check-types as part of the ci build to prevent this ?

@RafaPolit @fnocetti Did you solve this issue ? I'm facing the same problem here .

@RafaPolit @fnocetti we should include yarn check-types as part of the ci build to prevent this ?

Maybe we can try it. I think it's a good idea to have our tools catch everything they can but, also, this was a silly mistake on my end, and should have been really straightforward to detecting prior to pushing to the repo.

@RafaPolit @fnocetti Did you solve this issue ? I'm facing the same problem here .

@m98jk I'm sorry to hear that. Are you experiencing any functionality not working properly or is it only the warnings in the terminal?

A fix for this is already considered in #2828 but it is still work in progress, so we should expect a few more days for it to be merged.

@fnocetti #2828 is only addressing the parts relevant to the packages introduced by that PR. There are still issues with the CSVLoader that are not being taken care by any current PR.

@m98jk This is just a development issue, for the time being.

That means, it is an issue for creating new code and running DEV instances. For production scenarios, this should be a non-issue.

$ yarn production-build
$ yarn run-production

should show no errors and is the way the application should be run for non-dev environments.

Hope this helps.

@fnocetti @RafaPolit
I clone the project then run yarn install with all dependences installed
and When I run yarn hot I got a long errors list

I paste it here https://pastebin.com/eKgMHGkT

and the first 30 lines is

```yarn run v1.22.4
$ export HOT=true; export BABEL_ENV=debug; npm run watch-types & npm run dev-server & npm run webpack-server

[email protected] watch-types /home/m98jk/Desktop/projects/uwzi/uwazi
tsc --noEmit --pretty --watch --preserveWatchOutput

[email protected] webpack-server /home/m98jk/Desktop/projects/uwzi/uwazi
node ./webpack/webpack.server.js

[email protected] dev-server /home/m98jk/Desktop/projects/uwzi/uwazi
nodemon ./server.js --ignore 'app/dist/*' --watch 'app/api' --watch 'app/shared' --ext 'ts js tsx'

[10:25:06 AM] Starting compilation in watch mode...

[nodemon] 1.17.2
[nodemon] to restart at any time, enter rs
[nodemon] watching: /home/m98jk/Desktop/projects/uwzi/uwazi/app/api//* /home/m98jk/Desktop/projects/uwzi/uwazi/app/shared//*
[nodemon] starting node ./server.js
clean-webpack-plugin: /home/m98jk/Desktop/projects/uwzi/uwazi/dist/* has been removed.
==> Connecting to mongodb://localhost/uwazi_development
2020-05-19T07:26:43.446Z [localhost]
uncaught exception or unhandled rejection, Node process finished !!
Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
[nodemon] app crashed - waiting for file changes before starting...
app/api/auth2fa/routes.ts:24:5 - error TS2345: Argument of type '(req: Request, res: Response, next: NextFunction) => void | Response' is not assignable to parameter of type 'Middleware'.
Types of parameters 'req' and 'req' are incompatible.
Type '{ user: User; body: any; }' is missing the following properties from type 'Request': get, header, accepts, acceptsCharsets, and 76 more.

24 needsAuthorization(['admin', 'editor']),
~~~~~~~~~~~

app/api/auth2fa/routes.ts:26:12 - error TS7006: Parameter 'req' implicitly has an 'any' type.

26 async (req, res, next) => {
~~~

app/api/auth2fa/routes.ts:26:17 - error TS7006: Parameter 'res' implicitly has an 'any' type.

26 async (req, res, next) => {
~~~

app/api/auth2fa/routes.ts:26:22 - error TS7006: Parameter 'next' implicitly has an 'any' type.

26 async (req, res, next) => {
~~~~

app/api/auth2fa/routes.ts:38:5 - error TS2345: Argument of type '(req: Request, res: Response, next: NextFunction) => void | Response' is not assignable to parameter of type 'Middleware'.

38 needsAuthorization(['admin', 'editor']),```

@m98jk type errors are being fixed and should not be a problem for you.

Error: connect ECONNREFUSED 127.0.0.1:27017
this one suggests that you do not have a mongodb server running or you do not have it running on the default port 27017

uwazi-err

@daneryl
I've checked mongo and run it again , but I get the same

mongodb on port 127.0.0.1:59006"

@m98jk mongodb connection error is gone now 馃憤
is this for development ? if not, you should not use yarn hot, there is no need to run nodemon on an non development environment, if this is the case ill recommend running production uwazi:

yarn production-build
yarn run-production

anyaway, the error now is that nodemon has reached system's file watchers limit, take a look at this if you want to go with the development environment yarn hot option

@daneryl It's for development , but The same errors here .
It's show me that there is errors in the code although I did not change the code .

uwazi2

@m98jk try yarn blank-state before yarn hot to set up a default blank state database.

also check versions of node and typescript pls.

@daneryl thank you , It's running on port 3000

Was this page helpful?
0 / 5 - 0 ratings