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

"Cannot find module" error when calling query within another query #2434

Open
minajevs opened this issue Dec 30, 2024 · 0 comments
Open

"Cannot find module" error when calling query within another query #2434

minajevs opened this issue Dec 30, 2024 · 0 comments

Comments

@minajevs
Copy link

Describe the bug
On a server, calling a query from another query throws an error Error [ERR_MODULE_NOT_FOUND]: Cannot find module ....

To Reproduce
Sample repo

  1. Create 2 very basic queries
query getFirstName {
  fn: import {getFirstName} from "@src/getFirstName",
  entities: []
}

query getFullName {
  fn: import {getFullName} from "@src/getFullName",
  entities: []
}
  1. Implement first query and import some external function into the query file:
import { type GetFirstName } from "wasp/server/operations";
import { capitalize } from "./capitalize"; // <-------- Important external import! 

export const getFirstName: GetFirstName<never, string> = () => {
  return capitalize("john");
};
  1. Implement second query and call first query from that
import { getFirstName, type GetFullName } from "wasp/server/operations";

export const getFullName: GetFullName<never, string> = async () => {
  const firstName = await getFirstName(); // <-------- Calling first query!
  return `${firstName} Smith`;
};
  1. Call a query from client
 const { data } = useQuery(getFullName);

Observed behavior
Server crashes with the following error:

[ Server!] Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/***/dev/wasp-bug-sample/.wasp/out/sdk/wasp/dist/ext-src/capitalize' imported from /Users/***/dev/wasp-bug-sample/.wasp/out/sdk/wasp/dist/ext-src/getFirstName.js
[ Server!]     at finalizeResolution (node:internal/modules/esm/resolve:257:11)
[ Server!]     at moduleResolve (node:internal/modules/esm/resolve:913:10)
[ Server!]     at defaultResolve (node:internal/modules/esm/resolve:1037:11)
[ Server!]     at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:650:12)
[ Server!]     at #cachedDefaultResolve (node:internal/modules/esm/loader:599:25)
[ Server!]     at ModuleLoader.resolve (node:internal/modules/esm/loader:582:38)
[ Server!]     at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:241:38)
[ Server!]     at ModuleJob._link (node:internal/modules/esm/module_job:132:49) {
[ Server!]   code: 'ERR_MODULE_NOT_FOUND',
[ Server!]   url: 'file:///Users/***/dev/wasp-bug-sample/.wasp/out/sdk/wasp/dist/ext-src/capitalize'

Removing external import (i.e. removing import { capitalize } from "./capitalize"; and inlining capitalize function) fixes the issue.

Environment

  • Apple Sillicon
  • Node.js v22.11.0
  • Wasp 15.0

Additional context

It is possible to "work around" the issue by commenting out problematic line, thefore causing build error, and then uncommenting the line again. I would speculate that there's a race condition during build time and external module (capitalize) is being built later than query (getFirstName)

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

No branches or pull requests

1 participant