You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement first query and import some external function into the query file:
import{typeGetFirstName}from"wasp/server/operations";import{capitalize}from"./capitalize";// <-------- Important external import! exportconstgetFirstName: GetFirstName<never,string>=()=>{returncapitalize("john");};
Implement second query and call first query from that
import{getFirstName,typeGetFullName}from"wasp/server/operations";exportconstgetFullName: GetFullName<never,string>=async()=>{constfirstName=awaitgetFirstName();// <-------- Calling first query!return`${firstName} Smith`;};
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)
The text was updated successfully, but these errors were encountered:
Hey @minajevs, I finally found the time to dig into this.
The short version: Change ./capitalize to ./capitalize.js and everything should work. You must specify the js extension for relative imports in server-side code (the client-side code will tolerate both js and no extension).
The easiest way is always to use the .js extension.
The long version
Import extensions are one of Wasp DX's biggest pain points. Learn the details here if you're curious: #2222.
P.S. I just created a new issue (#2440) to cover this problem. We accidentally closed the one covering it (#1363 (comment)) because it also discussed a different problem (which we solved).
So, thanks for the report!
Moral of the story: Respect to the Single responsibility principle when writing issues :)
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
Observed behavior
Server crashes with the following error:
Removing external import (i.e. removing
import { capitalize } from "./capitalize";
and inliningcapitalize
function) fixes the issue.Environment
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
)The text was updated successfully, but these errors were encountered: