Add `"types"` entries to the `"exports"` property of `package.json`, to allow consumption from Typescript with the new `Node16` module resolution strategy
See original GitHub issueIs your feature request related to a problem? Please describe.
I’m unable to consume "@graphql-yoga/common"
from Typescript 4.7, when module resolution is set to Node16
Describe the solution you’d like
Add "types"
entries to the "exports"
property of package.json
Describe alternatives you’ve considered
None
Additional context
The following should suffice
"exports": {
".": {
"types": "./index.d.ts",
"require": "./index.js",
"import": "./index.mjs"
},
"./*": {
types": "./*.d.ts",
"require": "./*.js",
"import": "./*.mjs"
},
"./package.json": "./package.json"
}
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:16
Top Results From Across the Web
Documentation - Module Resolution - TypeScript
There are two possible module resolution strategies: Node and Classic. You can use the moduleResolution option to specify the module resolution strategy.
Read more >TypeScript module "Node16" does not resolve types of CJS ...
Either 1) adding an explicit types property to the package.json or 2) moving the types to ./lib/index.d.js "fixes" the problem.
Read more >New package.json `exports` field not working with TypeScript
json field, called exports , to select and rewrite exported files. But Typescript raises the 2307 error, saying that module is not found....
Read more >TypeScript and native ESM on Node.js - 2ality
json and support two important features: Hiding internals: Without property "exports" , every module in my-package can be accessed via deep ...
Read more >How we employed the new ECMAScript Module Support in ...
The most obvious difference between ESM and CommonJS is the use of import and export vs the use of require and module.exports ....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Duncan3142 This is now fixed in this release https://github.com/dotansimha/graphql-yoga/pull/1303 😇
@graphql-yoga/common@2.9.0
@n1ru4l There is one more thing I noticed in the code for your PR which would result in divergent behaviour, though my previous comments still apply. The package.json in the root of your forked repo is missing
"type": "module"
This means typescript will always treat .ts files as commonjs files, so imports in those files will always transpile to ‘require’. This would break the consumption of ‘@repeaterjs/repeater’
If the “type” field is missing or set to “commonjs”, typescript files need to have the .mts extension to be treated as ESM
The following links go into detail:
Typescript 4.7 File Extensions Typescript 4.7 Package Imports/Exports Node package docs