question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Is 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:closed
  • Created a year ago
  • Reactions:3
  • Comments:16

github_iconTop GitHub Comments

2reactions
n1ru4lcommented, Jun 27, 2022

@Duncan3142 This is now fixed in this release https://github.com/dotansimha/graphql-yoga/pull/1303 😇

@graphql-yoga/common@2.9.0

1reaction
Duncan3142commented, Jun 21, 2022

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found