Hey all - getting this runtime issue when sending ...
# help
c
Hey all - getting this runtime issue when sending a graphql request to my apollo api deployed with SST. anyone seen this before??
Copy code
Runtime.ImportModuleError: Error: Cannot find module 'ts-tiny-invariant'
Require stack:
- /var/task/server.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js
    at _loadUserApp (/var/runtime/UserFunction.js:100:13)
    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)
    at Object.<anonymous> (/var/runtime/index.js:43:30)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
f
Hey @colin, did you try running
sst start
and see if the apollo api works?
p
Hi @colin, I've been using it for a couple of weeks but haven't seen that issue before unfortunately. Maybe you're using a different version of a package to me though?
c
Hmm, what version are you on @Phil? So this only happens with I run an
sst deploy
to a different stage @Frank. When I run
sst start
things seem to be working fine..
or really, to be more specific, when I push up to seed and have the auto deploy kick off through seed.
update: Seems to work when i run
sst start
this error goes away. After a successful query I tried to run
sst deploy
and I got the same error. The module seems to be some kind of typescript dependency. So maybe something is off in the sst deploy/build step? Didn’t notice anything too weird in the build logs
p
@colin I'm using 0.35.1 of SST atm
I haven't tried deploying to a different stage though
c
Hmm okay, once you do let me know if you have the same problem. Seems there is some sort of dependency mismatch. Found this issue: https://github.com/apollographql/apollo-server/issues/5505
Something to do with Typescript compilation under the hood
f
Hey @colin, I’m looking at the GH issue above, are you using any
@graphql-tools
modules in ur dependencies?
c
Only as a dependency of
apollo-server-core
not in any of my own root packages
f
I see. Often this error happens when the missing module was required dynamically.
As a sanity check, can you try force including the module via the
bundle
option?
Copy code
bundle: {
  nodeModules: ["apollo-server-core"],
}
c
Okay update: including the above option seems to have worked! Could you help me understand as to why that would have fixed @Frank
f
It seems
ts-tiny-invariant
is being required dynamically. When packaging the code, esbuild traverse through all requires/imports to include the relevant code that are used, instead of including the entire
node_modules
folder. But if modules are included dynamically/conditionally at runtime, esbuild will ignore them.
By specifying
nodeModules
, SST will package the entire
apollo-server-core
package including all of its
node_modules
, which should include the
ts-tiny-invariant
package.
Let me know if that makes sense.
c
Got it - It also seems this will be fixed shortly once apollo-server merges this: https://github.com/apollographql/apollo-server/pull/5552 They removed the bad dependency.
f
ah i see