@Types 没有使用正确的模块(Typescript、http-proxy-middleware、webpack、react) [英] @Types is not using the correct module (Typescript, http-proxy-middleware, webpack, react)

查看:203
本文介绍了@Types 没有使用正确的模块(Typescript、http-proxy-middleware、webpack、react)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用与 这个 repo 类似的设置来尝试创建一个使用 React 和 Express 的全栈打字稿应用.

I'm trying to use a similar setup to this repo to try and create a fullstack typescript app using React and Express.

repo 使用类似 nodemon 的 tsc-watch 来监视服务器文件,然后使用 webpack-dev-server 在端口 8085 托管 react 静态文件.同时,运行在 3000 上的服务器通过将所有静态请求代理到 8085 处的/statics.

The repo uses tsc-watch like nodemon to keep an eye on the server files, and then webpack-dev-server to host the react static files at port 8085. Meanwhile the server, running on 3000, renders the react app by proxying all static requests to /statics at 8085.

当我克隆 repo 时,一切正常.但是,在我自己的存储库中(我正在尝试学习如何进行类似的配置,服务器不断抛出此错误:

When I clone the repo everything works. However, in my own repo (where I'm trying to learn how to do a similar configuration, the server keeps throwing up this error:

node_modules/@types/webpack-dev-server/index.d.ts

node_modules/@types/webpack-dev-server/index.d.ts

然后:

node_modules/http-proxy-middleware/dist/index"'没有导出成员配置".

node_modules/http-proxy-middleware/dist/index"' has no exported member 'Config'.

当我进入 node_modules 时,我可以看到 @types/webpack-dev-server 期望有来自 http-proxy-middleware 的 Config.在@types/http-proxy-middleware 中,有一个名为 Config 的接口.但是,在正常的 http-proxy-middleware 节点模块文件夹中,没有,这就是导致错误的原因.

When I go into node_modules, I can see that @types/webpack-dev-server is expecting there to be Config from http-proxy-middleware. In @types/http-proxy-middleware, there is an interface called Config. However, in the normal http-proxy-middleware node module folder, there is not, and this is what is causing the error.

我的问题是如何让@types/webpack-dev-server 使用@types/http-proxy-middleware,而不仅仅是 node_modules/http-proxy-middleware?还是我完全错过了其他东西?

My question is how do I get @types/webpack-dev-server to use @types/http-proxy-middleware, rather than just node_modules/http-proxy-middleware? Or am I missing something else entirely?

如果需要,我可以发布代码.

I can post code if needed.

推荐答案

以下几点可能有帮助:

  • statics-router.ts 正在使用 http-proxy-middleware,版本"^1.0.3"
  • webpack-dev-server 依赖于版本 "0.19.1"
  • http-proxy-middleware 上的 Config 在版本 1 中被移除.
  • 版本 1 的类型定义是 http-proxy-middleware 本身的一部分(而不是像以前那样在 @types 下)
  • 如果你查看 /node_modules/@types/webpack-dev-server/package.json,你会在 dependencies 上看到它有:@types/http-proxy-middleware":*".请注意,它依赖于 .d.ts
  • @types 版本
  • The statics-router.ts is using http-proxy-middleware, version "^1.0.3"
  • webpack-dev-server is dependent on version "0.19.1"
  • The Config on http-proxy-middleware was removed in version 1.
  • The type definitions for version 1 are part of http-proxy-middleware itself (And not under @types like before)
  • If you look into /node_modules/@types/webpack-dev-server/package.json, you will see that on the dependencies it has: "@types/http-proxy-middleware": "*". Notice that it's dependend on the @types version of the .d.ts

看起来 typescript 首先在 node_modules/LIBRARY 下搜索类型定义,然后在 @types 下搜索,所以它找到"了版本 1 的 .d.ts,而不是版本 0.19.1webpack-dev-server 需要

It looks like typescript is searching for the type definitions under node_modules/LIBRARY first, and then under @types so it "finds" the .d.ts for version 1, instead of version 0.19.1 like webpack-dev-server requires

要解决这个问题,只需添加:skipLibCheck":true,到共享的tsconfig.json

To solve this just add: "skipLibCheck": true, to the shared tsconfig.json

这篇关于@Types 没有使用正确的模块(Typescript、http-proxy-middleware、webpack、react)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆