Problem
I have a pnpm workspace monorepo with the following structure:
- A shared tsconfig package
- A shared database package
- A NextJS app
- A new google cloud function app
While the shared database package works perfectly with my NextJS app, I'm encountering TypeScript errors when trying to use it in Google Cloud Functions.
atralvarez@atralvarez repo % pnpm run start:serverless
> [email protected] start:serverless /dev/code/repo
> pnpm --filter @repo/serverless-function start
> @repo/[email protected] start /dev/code/repo/apps/serverless-function
> functions-framework --target=handler
Provided module can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/dev/code/repo/packages/database/dist/schema' is not supported resolving ES modules imported from /dev/code/repo/packages/database/dist/index.js
at finalizeResolution (node:internal/modules/esm/resolve:258:11)
at moduleResolve (node:internal/modules/esm/resolve:917:10)
at defaultResolve (node:internal/modules/esm/resolve:1130:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:36)
Could not load the function, shutting down.
Repository
I've created a minimal reproduction repository that demonstrates the issue.
What I've tried
I know I could use workarounds like explicitly importing with .js extensions despite files being .ts, but I'm looking for a clean solution that maintains proper TypeScript integration.
Thanks in advance!
Problem
I have a pnpm workspace monorepo with the following structure:
- A shared tsconfig package
- A shared database package
- A NextJS app
- A new google cloud function app
While the shared database package works perfectly with my NextJS app, I'm encountering TypeScript errors when trying to use it in Google Cloud Functions.
atralvarez@atralvarez repo % pnpm run start:serverless
> [email protected] start:serverless /dev/code/repo
> pnpm --filter @repo/serverless-function start
> @repo/[email protected] start /dev/code/repo/apps/serverless-function
> functions-framework --target=handler
Provided module can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/dev/code/repo/packages/database/dist/schema' is not supported resolving ES modules imported from /dev/code/repo/packages/database/dist/index.js
at finalizeResolution (node:internal/modules/esm/resolve:258:11)
at moduleResolve (node:internal/modules/esm/resolve:917:10)
at defaultResolve (node:internal/modules/esm/resolve:1130:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:36)
Could not load the function, shutting down.
Repository
I've created a minimal reproduction repository that demonstrates the issue.
What I've tried
I know I could use workarounds like explicitly importing with .js extensions despite files being .ts, but I'm looking for a clean solution that maintains proper TypeScript integration.
Thanks in advance!
Share Improve this question edited Mar 10 at 12:10 atralvarez asked Mar 10 at 12:01 atralvarezatralvarez 112 bronze badges 1- On Stack Overflow, do not require the reader to use links to external information. Everything should be in the question itself so future readers always have immediate access to it. If you have code, copy and paste it into the question so it's easy to read, copy, and search. – Doug Stevenson Commented Mar 10 at 12:41
1 Answer
Reset to default 0Node.js doesn’t seem to support directory imports based on this documentation. You have to explicitly point to your .js file for example:
import …from “./database/index.js”
You may also find the suggestions in this old SO post helpful for your case.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744848025a4596960.html
评论列表(0条)