Closed
Description
% 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';