Skip to content

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

@anniefu anniefu requested a review from matthewrobertson May 10, 2022 21:22
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

@koistya koistya force-pushed the fix-typescript-exports branch from 6d92c32 to 6e2fd8e Compare May 25, 2022 07:31
@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.

@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.

@koistya koistya deleted the fix-typescript-exports branch July 17, 2022 20:04
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.

5 participants