Skip to content

Module '"graphql-http"' has no exported member '...' happens with ESM TypeScript #70

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

Closed
akiym opened this issue Mar 31, 2023 · 4 comments
Labels
bug Something isn't working released Has been released and published

Comments

@akiym
Copy link

akiym commented Mar 31, 2023

Screenshot
Screenshot 2023-03-31 at 15 12 15

% yarn run -s ts-node-esm test.ts
warning package.json: No license field
/private/tmp/a/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
test.ts:1:10 - error TS2305: Module '"graphql-http"' has no exported member 'createHandler'.

1 import { createHandler } from 'graphql-http';
           ~~~~~~~~~~~~~

    at createTSError (/private/tmp/a/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/private/tmp/a/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/private/tmp/a/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/private/tmp/a/node_modules/ts-node/src/index.ts:1433:41)
    at transformSource (/private/tmp/a/node_modules/ts-node/src/esm.ts:400:37)
    at /private/tmp/a/node_modules/ts-node/src/esm.ts:278:53
    at async addShortCircuitFlag (/private/tmp/a/node_modules/ts-node/src/esm.ts:409:15)
    at async nextLoad (node:internal/modules/esm/loader:163:22)
    at async ESMLoader.load (node:internal/modules/esm/loader:605:20)
    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:11) {
  diagnosticCodes: [ 2305 ]
}

Expected Behaviour
I expected it to work importing graphql-http module with ESM TypeScript.

Actual Behaviour
but instead it did fail with Module '"graphql-http"' has no exported member '...' error.

Debug Information
test.ts

import { createHandler } from 'graphql-http';

package.json

{
  "type": "module",
  "dependencies": {
    "graphql": "^16.6.0",
    "graphql-http": "^1.17.0"
  },
  "devDependencies": {
    "ts-node": "^10.9.1",
    "typescript": "^5.0.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "moduleResolution": "nodenext",
    "strict": true
  }
}

Further Information

Looking at the type definition of graphql-http in node_modules/graphql-http/lib/index.d.mts, there is no .js extension.

export * from './common';
export * from './handler';
export * from './client';
export * from './audits';

It may works correctly by changing the following code:

export * from './common.js';
export * from './handler.js';
export * from './client.js';
export * from './audits/index.js';
@benjie
Copy link
Member

benjie commented Mar 31, 2023

This is the correct thing to do (even though the files are TypeScript you must use a .js extension), and you can enable a lint rule to enforce it:

“import/extensions": ["error", "ignorePackages"],

@enisdenjo enisdenjo added the bug Something isn't working label Mar 31, 2023
enisdenjo pushed a commit that referenced this issue Mar 31, 2023
## [1.17.1](v1.17.0...v1.17.1) (2023-03-31)

### Bug Fixes

* Add file extensions to imports/exports in ESM type definitions ([d084a8d](d084a8d)), closes [#70](#70)
* **audits/server:** Better "must accept UTF-8" test with emoji ([#69](#69)) ([a322d2c](a322d2c))
@enisdenjo
Copy link
Member

🎉 This issue has been resolved in version 1.17.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@enisdenjo enisdenjo added the released Has been released and published label Mar 31, 2023
@enisdenjo
Copy link
Member

I have fixed this in my ESM post processing script. Can you update to v1.17.1 and try again? Thanks!

@akiym
Copy link
Author

akiym commented Mar 31, 2023

Thank you for fixing so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Has been released and published
Projects
None yet
Development

No branches or pull requests

3 participants