-
Notifications
You must be signed in to change notification settings - Fork 161
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
Error importing types when moduleResolution is set to nodenext #521
Comments
This is broken on ES6 and above, not just nodeNext. Package.json "dependencies": {
"@google-cloud/functions-framework": "^3.1.3",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"gts": "^3.1.1",
"helmet": "^6.0.1",
"http-errors": "^2.0.0",
"morgan": "^1.10.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/cookie-parser": "^1.4.3",
"@types/cors": "^2.8.13",
"@types/http-errors": "^2.0.1",
"@types/mocha": "^10.0.1",
"@types/morgan": "^1.9.4",
"@types/node": "^18.14.6",
"@types/supertest": "^2.0.12",
"gts": "^3.1.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"pre-commit": "^1.2.2",
"supertest": "^6.3.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.2",
"typescript": "~4.9.5"
} .eslintrc.json {
"extends": "./node_modules/gts/",
"rules": {
"node/no-unpublished-import": 0
}
} index.test.js import getFunction from '@google-cloud/functions-framework/testing'; Error message Cannot find module '@google-cloud/functions-framework/testing' or its corresponding type declarations.ts(2307) |
They need to fix the type mappings. This is ridiculous for a cloud provider to be so far behind like this. If I wasn't forced into GCP I'd go back to AWS. |
Hi all, sorry you've been running into some trouble here. I think there are two separate issues that you both have been running into that both stem from our use of an We declare the exports here as:
From the docs on the exports feature https://nodejs.org/api/packages.html#main-entry-point-export when module resolution is respecting this property all other paths in the module should be hidden and only the exported paths are available to import. This means that when using
When using older module resolution strategies i.e.
All of this is to say, the preferred fix should be to update your module resolution strategy to
Hope this helps! |
Problem
Given a simple Cloud Function written in TypeScript:
With a
tsconfig.json
having:The following error is generated:
This error can be resolved by changing
moduleResolution
tonode
instead ofnodenext
.Demonstration
demo.mov
Steps to reproduce
.yarn/sdks/typescript
when promptedsrc/index.ts
and observe the errortsconfig.json
and changemoduleResolution
tonode
Related GitHub issues
Related StackOverflow questions
Questions
nodenext
and what can be done to resolve it without switching tonode
?PubsubMessage
from@google-cloud/pubsub/build/src/publisher
work without errors?Context
in@google-cloud/functions-framework/build/src/functions
that would cause one to have an error and not the other?The text was updated successfully, but these errors were encountered: