如图所示,明明安装了
react-copy-to-clipboard,在引用的
时候还是提示Could not find a
declaration file for
module ‘
react-copy-to-clipboard’.
解决办法:
如果是在
ts环境下,就看一下有没有
ts版本的包
npm install “@types/***”
我这里是 npm install “@types/
react-copy-to-clipboard”
然后就不
报错了
有的npm包使用原生js没问题,换ts后某些包会报“Could not find a declaration file for module”的错误。
有以下两种方式解决
1、下载 @type/报错包(部分包开发者可能没有上传自己的.d.ts代码到npm分支,这时会报错说找不到这个包,别急看下一步)
2、最直接简单有效的解决方法:项目根目录下新建shims-vue.d.ts文件
//declare声明宣告, 声明一个ambient module(即:没有内部实现的 module声明)
declare .
Uncaught Error: useRoutes() may be used only in the context of a component.
Uncaught Error: A is only ever to be used as the child of element, never rendered directly.
Uncaught Error: useHref() may be used only in the context of
1.ts中使用路径别名报错
在react中通常路径别名都是在webpack的webpack.config.js文件中配置的,但是在引入了ts之后,webpack中的路径别名引用失效了
此时我们需要在跟src文件同级目录的tsconfig.json文件中添加配置:
注意要在compilerOptions中添加
"compilerOptions": {
"target": "es6" /**指定ECMAScript目标版本**/,
"modu
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/
react": "^9.3.2",
"@testing-li..