Hi,
I used the @types/http-proxy-middleware which expord a Config type. When i upgrade to the last version of http-proxy-middleware, i have the following error with this code:
import createProxyMiddleware, { Options } from 'http-proxy-middleware';
TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
Can you export the Options type in index.d.ts?
Regards
You could import the types like
import { IRequestHandler, Options } from 'http-proxy-middleware/dist/types';
but I concur that it would be better to export them directly from the module.
However there are more problems with the new types.
If you're using ES6 as target it fails with:
node_modules/http-proxy-middleware/dist/types.d.ts(2,8): error TS1192: Module '"/node_modules/@types/express/index"' has no default export.
node_modules/http-proxy-middleware/dist/types.d.ts(3,8): error TS1192: Module '"http"' has no default export.
node_modules/http-proxy-middleware/dist/types.d.ts(4,8): error TS1192: Module '"/node_modules/@types/http-proxy/index"' has no default export.
node_modules/http-proxy-middleware/dist/types.d.ts(5,8): error TS1192: Module '"net"' has no default export.
Importing them like below in types.ts it works.
import * as express from 'express';
import * as http from 'http';
import * as httpProxy from 'http-proxy';
import * as net from 'net';
Ouch, this old decision of using default exports is biting me now...
https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module
It:
Options typeThink it can be solved by:
"esModuleInterop": true in tsconfig.json (https://github.com/chimurai/http-proxy-middleware/blob/master/tsconfig.json#L9)@ghostd @bender316 Is the type issue a blocker for HPM functioning at all?
I made a new version with the changes mentioned earlier.
Can you give [email protected] a try?
example usage:
import { createProxyMiddleware, Options } from 'http-proxy-middleware';
Let me know if this works out
Yes, works now for ES6. IRequestHandler is still not exported though.
It works for me, thanks
Published version v1.0.0 to npm
More details: https://github.com/chimurai/http-proxy-middleware/releases
@bender316
RequestHandler is now exported also. (removed the I prefix from interface name)
Thanks for reporting the issue! Hope it didn't cause too much inconvenience.
Hi I'm not sure if this is relevant but webpack-dev-server is kicking up a fuss with 'node_modules/http-proxy-middleware/dist/index"' has no exported member 'Config'.' Here is my tsconfig:
{
"compilerOptions": {
"target": "ES2019",
"sourceMap": true,
"module": "commonjs",
"esModuleInterop": true,
"declaration": true,
"resolveJsonModule": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"outDir": "../../dist/server",
"lib": ["ES2019"],
"moduleResolution": "node",
"types": ["node"],
"incremental": true,
"composite": true
},
"include": ["**/*.ts"],
"exclude": ["**/*.test.ts"],
"references": [{ "path": "../shared" }]
}
Most helpful comment
Published version
v1.0.0to npmMore details: https://github.com/chimurai/http-proxy-middleware/releases
@bender316
RequestHandleris now exported also. (removed theIprefix from interface name)Thanks for reporting the issue! Hope it didn't cause too much inconvenience.