Mypy typing errors when upgrading to Twisted 21.2.0 - twisted

In trying to upgrade the Twisted package from 20.3.0 to 21.2.0.
After the upgrade, when running Mypy I'm getting the following errors when accessing the reactor (from twisted.internet import reactor):
error: Module has no attribute "run" [attr-defined]
error: Module has no attribute "running" [attr-defined]
error: Module has no attribute "running" [attr-defined]
error: Module has no attribute "callLater" [attr-defined]
error: Module has no attribute "callInThread" [attr-defined]
error: Module has no attribute "callFromThread" [attr-defined]
error: Module has no attribute "spawnProcess" [attr-defined]
error: Module has no attribute "spawnProcess" [attr-defined]
When running Mypy with reveal_type(reactor):
Revealed type is '_importlib_modulespec.ModuleType'
I'm trying to understand what is the best way to handle this situation without just ignoring the errors so I can have the type checking when using the reactor.
Is there a better way to import the reactor? Is there a way to mark the type of the reactor for Mypy? should I cast it to a type every time before using it?

This seems to be an assigned bug in Twisted (https://twistedmatrix.com/trac/ticket/9909) and the proposed fix sounds like a breaking change.
One of the comments on their Trac describes casting it, as you suggest, as a workaround:
from typing import cast
import twisted.internet.reactor
from twisted.internet.interfaces import IReactorCore
reactor = cast(IReactorCore, twisted.internet.reactor)
reactor.run()

It took a ridiculous amount of searching but I finally found the solution in the Twisted source code itself. Add the following comment to the end of your line:
# type: ignore[attr-defined]
for example:
reactor.callFromThread(reactor.stop) # type: ignore[attr-defined]
That will "fix" it.

Related

Error with the dependency of a dependency in nodejs

I have forked a repo to here:
https://github.com/unegma/react-three-fpscontrols
and am trying to convert the package to use typescript..
The error I keep getting is:
TypeError: three_1.Vector3 is not a constructor
which is occurring on this line here:
https://github.com/unegma/react-three-fpscontrols/blob/c89176ab5ce71e8e89332c088047ff85f804306e/src/FPSControls.tsx#L11
Checking the 'three' object in my console shows this: /static/media/three.c679b86df6ce78a00d67.cjs
instead of an Object containing Vector3, which leads me to think I'm doing the import of the import incorrectly.
I've tried including the #types/three in the dev dependencies, and the dependencies, and the peer dependencies, but nothing seems to work. Any clues?

Cannot use import statement outside a module when using wrangler v2

I'm new to using cloudflare and wrangler. I've a project that I've been working on, and I'm now trying to deploy it using wrangler publish, but I keep running into issues. My product is coded in node.js, and I'm using version 2 of wrangler. When I execute wrangler publish I get:
Basic JavaScript project found. Skipping unnecessary build!
Error: Something went wrong with the request to Cloudflare...
Uncaught SyntaxError: Cannot use import statement outside a module
at worker.js:2Basic JavaScript project found. Skipping unnecessary build!
Error: Something went wrong with the request to Cloudflare...
Uncaught SyntaxError: Cannot use import statement outside a module
at worker.js:2
I've searched for a solution, and one of them that I found said to change module in wrangler.toml from type="javascript"to type="webpack" however that gives me a bunch of errors:
./node_modules/destroy/index.js
Module not found: Error: Can't resolve 'fs' ... Parsed request is a module...resolve as module
/Users/Desktop/APIs/cpiCalculator2/node_modules/destroy/node_modules doesn't exist or is not a directory
...
Error: webpack returned an error. You may be able to resolve this issue by running npm install.
I've tried reinstalling npm as it suggests and then wrangler publish again, but that just gives me the same error message.
I'm really not sure what the issue is, and I would really appreciate any help or advice on how to resolve this issue. Thank you!
Also, just a note, I'm not sure if this is affecting it, but I do have two other js documents in the main area of my project (where my index.js file is).

Vue Workbox Webpack "cannot use import statement outside a module"

I'm trying to use workbox for the first time but I always get the following error:
Uncaught SyntaxError: Cannot use import statement outside a module
This is my src-sw.js
import {precacheAndRoute} from 'workbox-precaching';
precacheAndRoute(self.__WB_MANIFEST);
I couldn't find anything in the workbox documentation in regards to this problem. How do I handle this?
You can check the Get Started guide to start using Workbox.
Also, you can not use ES modules in ServiceWorkers (yet). Check here for more info: https://stackoverflow.com/a/45578811/1273042

react-native-progress-webview Unable to resolve module

I found this project interesting at the NPM,
https://www.npmjs.com/package/react-native-progress-webview
however I followed the instruction, it shows the following error:
error: bundling failed: Error: Unable to resolve module `react-native-progess-webview` from `mycomponent.js`: Module `react-native-progess-webview` does not exist in the Haste module map
I already installed 'react-native-webview' and it works fine, however react-native-progess-webview seems not able to be imported.
I am just simply importing the library like this:
import ProgressWebView from "react-native-progess-webview";
How to solve?
I found that it is a typo in the tutorial, in the tutorial it is:
import ProgressWebView from "react-native-progess-webview";
but the correct one is:
import ProgressWebView from "react-native-progress-webview";
There is an "r" in the "progress".

Angular flex-layout in Ionic3... rxjs/operator not found?

Trying to use #angular/flex-layout in an existing npm-enabled Ionic 3 project.
Adding "FlexLayoutModule" to my main module's imports won't allow the app to start, saying that: cannot find module "rxjs/operators" is the cause.
Already cleared node_module, npm install, reinstalled Ionic CLI. Nothing helps. Could it be a version conflict? Moreover, I'm already using Observables in this project. I don't get it. And the import of "FlexLayoutModule" is in cause of this issue (disabling the import removes the issue).
Anyone could be successful at using flex-layout with ionic? I've seen this plunk, but it uses system.js, so not 100% reproducing my goal.
http://plnkr.co/edit/y8R0MF?p=info
Edit: a more verbose issue:
Uncaught (in promise): Error: Cannot find module "rxjs/operators"
Error: Cannot find module "rxjs/operators" at Object.580
(http://localhost:8100/build/22.main.js:319:7) at webpack_require
(http://localhost:8100/build/main.js:48:30) at Object.1021
(http://localhost:8100/build/22.main.js:11:79) at webpack_require
(http://localhost:8100/build/main.js:48:30) at
http://localhost:8100/build/main.js:122015:10 at t.invoke
(http://localhost:8100/build/polyfills.js:3:9283) at Object.onInvoke
(http://localhost:8100/build/main.js:4650:37) at t.invoke
(http://localhost:8100/build/polyfills.js:3:9223) at r.run
(http://localhost:8100/build/polyfills.js:3:4452) at
http://localhost:8100/build/polyfills.js:3:14076
I'm getting a similar error with Angular CLI. Everything is OK until I include FlexLayoutModule in the app's NgModule imports. Then I get the error:
Module not found: Error: Can't resolve 'rxjs/operators' in 'D:\dev\Vms.Signup.Client\node_modules\#angular\flex-layout\esm5'
I updated to the latest rxjs and that seems to have fixed it.