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

fix: TypeScript exports in package.json #461

Merged
merged 1 commit into from
Jun 6, 2022

Conversation

koistya
Copy link
Contributor

@koistya koistya commented May 3, 2022

import { getTestServer } from "@google-cloud/functions-framework/testing";
//                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Cannot find module '@google-cloud/functions-framework/testing' or its corresponding type declarations.ts(2307)

Ref microsoft/TypeScript#33079

Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the syntax here is correct for a fix. Does this work locally?

As a workaround, you can use the following import:

import { getTestServer } from "@google-cloud/functions-framework/build/src/testing";

".": "./build/src/index.js",
"./testing": "./build/src/testing.js"
".": {
"types": "./build/src/index.d.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "types" is valid here.

https://nodejs.org/api/packages.html#package-entry-points

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koistya
Copy link
Contributor Author

koistya commented May 22, 2022

@grant it works with at least the TypeScript version 4.7.1-rc. Note that tsconfig.json/moduleResolution needs to be set to Node16 or NodeNext for this to work; otherwise it will work exactly as before I believe (not a breaking change).

@TravisSperry
Copy link

Running into what might be a related issue with:

import { getTestServer } from '@google-cloud/functions-framework/build/src/testing'

Error: Package subpath './build/src/testing' is not defined by "exports"

This is with a fresh npx gts init

@penx penx mentioned this pull request Jun 6, 2022
Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems fine. We can go with it and revert if needed.

@grant grant merged commit 3596068 into GoogleCloudPlatform:master Jun 6, 2022
gcf-merge-on-green bot pushed a commit that referenced this pull request Jun 6, 2022
🤖 I have created a release *beep* *boop*
---


## [3.1.2](v3.1.1...v3.1.2) (2022-06-06)


### Bug Fixes

* TypeScript exports in package.json ([#461](#461)) ([3596068](3596068))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@dimip1606
Copy link

dimip1606 commented Jul 14, 2022

I'm still getting Cannot find module '@google-cloud/functions-framework/testing' or its corresponding type declarations.ts(2307) with v3.1.2 when using

import { getTestServer } from '@google-cloud/functions-framework/testing'

when "moduleResolution": "node" is set in tsconfig.json. Setting "moduleResolution": "NodeNext" fixes it.

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

Successfully merging this pull request may close these issues.

None yet

5 participants