Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typescript] Options type is not exported #400

Closed
ghostd opened this issue Feb 17, 2020 · 7 comments · Fixed by #402
Closed

[Typescript] Options type is not exported #400

ghostd opened this issue Feb 17, 2020 · 7 comments · Fixed by #402

Comments

@ghostd
Copy link

ghostd commented Feb 17, 2020

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

@bender316
Copy link

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';

@chimurai
Copy link
Owner

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:

  • prevents exporting Options type
  • causes the ES6 target issue

Think it can be solved by:


@ghostd @bender316 Is the type issue a blocker for HPM functioning at all?

@chimurai
Copy link
Owner

chimurai commented Feb 17, 2020

I made a new version with the changes mentioned earlier.
Can you give http-proxy-middleware@0.22.0-alpha a try?

example usage:

import { createProxyMiddleware, Options } from 'http-proxy-middleware';

Let me know if this works out

@bender316
Copy link

Yes, works now for ES6. IRequestHandler is still not exported though.

@ghostd
Copy link
Author

ghostd commented Feb 18, 2020

It works for me, thanks

@chimurai
Copy link
Owner

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.

@raph90
Copy link

raph90 commented Aug 20, 2020

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" }]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants