GoogleCloudPlatform / functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
Apache License 2.0
1.29k stars 158 forks source link

fix: TypeScript exports in package.json #461

Closed koistya closed 2 years ago

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

Ref https://github.com/microsoft/TypeScript/issues/33079

koistya commented 2 years ago

@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 commented 2 years ago

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

dimip1606 commented 2 years ago

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.