I opened my old project today and saw these strange warnings:
ERROR in src/App.tsx:13:17
TS2307: Cannot find module './App.module.css' or its corresponding type declarations.
11 | import { Layout, Breadcrumb } from 'antd'
12 | import Header from './components/Header/Header'
> 13 | import css from './App.module.css'
| ^^^^^^^^^^^^^^^^^^
14 | import { ROUTES } from './constants/routes'
15 | import Menu from './components/Menu'
16 |
ERROR in src/components/common/FormsControls/FormsControls.tsx:2:17
TS2307: Cannot find module './FormsControls.module.css' or its corresponding type declarations.
1 | import { FC, MouseEvent } from 'react'
> 2 | import css from './FormsControls.module.css'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | import commonCss from '../styles.module.css'
4 | import { Field, WrappedFieldProps } from 'redux-form'
5 | import cn from 'classnames'
There are also a lot of them with file formats svg, png and others. All my packages are now the most recent version.
There was no such problem before, can anyone help solve this without having to struggle with webpack?
Create a file called declarations.d.ts (you can name it anything you want)
Sometimes it is mandatory to reload your IDE but not always.
// declarations.d.ts
declare module '*.css';
declare module '*.scss';
declare module '*.svg';
// etc ...
TypeScript does not know that there are files other than .ts or .tsx hence it will complain if an import has an unknown file suffix, so in this case, we explicitly tell the compiler that we mean to load a module that can have the following extensions.
In my React app, created with CRA, I had to add in react-app-env.d.ts:
declare module '*.css';
Adding this declaration in separate file, like suggested above, did not work.
Related
So there's this video on YouTube that I am following along for building an Open Sea 2.0 clone using
Next.js, Replit, thirdweb, Infura, & Tailwind CSS. The chain used in the video is Rinkeby Network and as rinkeby is not stable anymore I am using goerli. But my code is stuck at:
erver.browser.development.js:5898:11)
error - pages/_app.js (7:23) # MyApp
ReferenceError: ChainId is not defined
5 | return(
6 | <ThirdWebProvider>
> 7 | desiredChainId = {ChainId.Goerli}
| ^
8 | chainRPC{{
9 | [ChainId.Goerli]: 'https://goerli.infura.io/v3/e5f83ad2d2814ff69492f524bd8a50a0'
10 | }}
Using replit as a sc editor. PS: I am a beginner so I decided to build through a follow along video.
Thanks!
I didn't understand what the issue is.
You need to import ChainId from here:
import { ThirdwebProvider, ChainId } from "#thirdweb-dev/react";
When I import
import 'antd/dist/antd.css';
these lines I got error like below.
Compiled with problems:X
Error:
Module parse failed: Unexpected token (13:6)
You may need an appropriate loader to handle this file type, currently
no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| /* stylelint-disable */
| /* stylelint-disable declaration-bang-space-before,no-duplicate-selectors,string-no-newline */
**> [class^=ant-]::-ms-clear,**
| [class*= ant-]::-ms-clear,
| [class^=ant-] input::-ms-clear,
How do I import packages in Python3?
-Package1
|
--InnerPackage1
||
| ---InnerInnerPackage1
| ---InnerInnerPackage2
| ---InnerInnerPackage3
--InnerPackage2
||---InnerInnerPackage4
||---InnerInnerPackage5
||---InnerInnerPackage6
||---InnerInnerPackage7
--InnerPackage3
||---InnerInnerPackage8
||---InnerInnerPackage9
|||
|| ----InnerInnerInnerPackage10
|| ----InnerInnerInnerPackage11
||---InnerInnerPackage12
|||----InnerInnerInnerPackage12
|||----InnerInnerInnerPackage13
|||----InnerInnerInnerPackage14
||---InnerInnerPackge13
Now, let my directory structure be similar to what I've mentioned above, how do I import a package, when my current directory is suppose InnerInnerInnerPackage12, and I have to import InnerInnerPackage6.
Though, when I import, while traversing above using this syntax,
from InnerPackage2 import InnerInnerPackage6
Else, one can also imply importing from the root package
Package1.InnerPackage2.InnerInnerPackage6
Another logic says,
import sys.path
sys.path.insert(0, '%package_directory%\\Package1\\InnerPackage2\\InnerInnerPackage6')
That works in cmd.
Still what would be the correct way to import a module.
It gives an error on running the code in CMD, but when I run the code in JetBrains PyCharm, it works.
Can someone help me out with this problem? Would be grateful! :)
Maybe this is because what we export from python is modules not packages.
I think this issue arises due to that.
Also, to run the same in cmd, one can follow this syntax:
from InnerPackage2.InnerInnerPackage6 import InnerInnerPackage6
This might be the reason, the difficulty arises when we run the same program in both JetBrains PyCharm and on cmd.
The IDE compiler shows these errors when using PowerMockito.
I tried both variants for specifying return values:
Variant 1
doReturn(jsonString).when(MyStaticClass.myStaticMethod());
Variant 2
when(MyStaticClass.myStaticMethod()).thenReturn(jsonString);
Why do the compiler display these errors?
I used
import static org.powermock.api.mockito.PowerMockito.when;
but you should use:
import static org.mockito.Mockito.when;
I had problem when I tried to import local directory qml files( they are in the another prefix in qml.qrc)
import QtQuick 2.0
import QtQuick.Controls 1.3
import QtQuick.Dialogs 1.2
import "Components"
//import "qrc:/Components/QMLs/Components"
Rectangle {
id: mainLocalRect
width: 300
height: 500
color: "orange"
HIcon {
id: hIcon
x: 0
y: 0
}
}
So that, I got error when deploying:
qrc:/QMLs/welcome.qml:4:1: "Components": no such directory
but there is directory Components and in Qt Creator HIcon is highlighted.
https://yadi.sk/i/eF1QKfxEhsdiY
I tried another way to import:
import "qrc:/Components/QMLs/Components"
And its works! But now SideMenu is not highlighted
https://yadi.sk/i/jmdgDZ4dhsdix
Structure of files in project:
main.qml
--QMLs/
----class.qml
----welcome.qml
....
----Components/
------HIcon.qml
Question: How to correctly to import directory?
You can use simply:
import "rel_path"
Where rel_path is the relative path from the point of view of the file that contains the import statement.
As an example, if the component C is in a child directory called D for the parent one, use:
import "../D/"
From now on, you can freely use C within your file.
The reason why highlighting does not work when using the correct qrc import is that QtCreator does not inspect the qrc file.
In addition you have to know how the resource system packages the files. Every file will be packaged with it's relative path to your .qrc file:
main.qml -> qrc:///main.qml
QMLs/welcome.qml -> qrc:///QMLs/welcome.qml
When using prefixes in your resource files those will be prepended to the relative path. (It's not that Qt 'copies' that file into the specified prefix/folder)
In your project that leads to the following situation:
QMLs/Components/SideMenu.qml -> qrc:///Components/QMLs/Components/SideMenu.qml
QMLs/Components/Helpers/MenuBackIcon.qml -> qrc:///Helpers/QMLs/Components/Helpers/MenuBackIcon.qml
It's not only a change in the absolute URL. It also 'moves' the files in the position relative to each other.
Now, to make things better you can specify an alies for each file in your .qrc file. An alias can just be a file name that will be combined with the prefix to make up the full URL:
Let's say you give the alias HIcon for your file QMLs/Components/HIcon.qml. That will lead to the situation that the full URL will be: qrc:///Components/HIcon.qml
Because your .qrc file is in the list of import paths you can now write your code like you'd expect:
import "Components"
[..]
HIcon {
[..]
}
Conclusion / TL;DR
Give each file an alias that is made up of the files name without the path.