Encountered an issue today where live lambda was w...
# sst
m
Encountered an issue today where live lambda was working but the deployed version failing. The culprit was the graphql module. Setting the NODE_ENV to production fixed the problem. I had to look in the compiled js file from a build to figure this out. Thought I'd share because the way live lambda is run vs. how the code is deployed is not the same and can result in some confusion.
Error: Cannot use e "__Schema" from another module or realm.
k
fwiw, I'm running into this problem as well - going to try the NODE_ENV workaround 😕
m
@Kelly Toole took me more hours than I want to admit to figure out. I ended up looking in the minified lambda code and searching for the error. Found it in the graphql package.
Odd thing is node_env isn't set anywhere. I had to set it in the lambda runtime configuration.
f
Hey @Mike McCall, is
NODE_ENV
set to
production
when u run sst start, and that’s why it works locally?
m
@Frank No it is not. I even built and deployed from a local comp and it was fine. FWIW the build is taking place on seed.
There is more too the graphql NODE_ENV check, but there is an explicit check for it. Did try setting NODE_ENV to production in seed. So I do assume it has to do with the build environment
f
Ah I see. Just ran a quick
echo $NODE_ENV
in SEED build server,
NODE_ENV
is
undefined
. What is it set to on ur local?
m
undefined
In seed I did set it using the environment
f
Can you send me a link to the build that failed on SEED?
m
Copy code
var Mh = process.env.NODE_ENV === "production" ? function (r, t) { return r instanceof t } : function (r, t) {
		if (r instanceof t) return !0; if (r) {
			var n = r.constructor, i = t.name; if (i && n && n.name === i) throw new Error("Cannot use ".concat(i, ' "').concat(r, `" from another module or realm.

Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.

<https://yarnpkg.com/en/docs/selective-version-resolutions>

Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.`))
		} return !1
	};
This is probably not too helpful but this is the error that is being thrown.
Copy code
var Mh = process.env.NODE_ENV === "production
I noticed this ^ and that's how I bypassed it
the seed build did not fail
the lambda runtime throws the error. Here is the full error. This isn't an uncommon error and does seem to be prevalent in ionic land. This does have to do with graphql module and not seed/sst. BUT that fact that it works with live lambda and locally, but not when deployed is the main concern.
Copy code
Error: Cannot use e "__Schema" from another module or realm.

Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.

<https://yarnpkg.com/en/docs/selective-version-resolutions>

Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
    at km (/var/task/src/api-stack/rules/eventBridgeToAppSync.js:1:8941)
    at bt (/var/task/src/api-stack/rules/eventBridgeToAppSync.js:12:5697)
    at ao (/var/task/src/api-stack/rules/eventBridgeToAppSync.js:12:5496)
    at Cl (/var/task/src/api-stack/rules/eventBridgeToAppSync.js:12:8294)
    at Gl (/var/task/src/api-stack/rules/eventBridgeToAppSync.js:12:8330)
    at new Ht (/var/task/src/api-stack/rules/eventBridgeToAppSync.js:12:8005)
    at Ht (/var/task/src/api-stack/rules/eventBridgeToAppSync.js:12:8023)
    at /var/task/src/api-stack/rules/eventBridgeToAppSync.js:34:8805
    at /var/task/src/api-stack/rules/eventBridgeToAppSync.js:1:249
    at /var/task/src/api-stack/rules/eventBridgeToAppSync.js:39:2994
f
Oh I see.. it seems it detected that process.env.NODE_ENV is not production (which is undefined), but then it also detected there are multiple versions of
graphql
modules installed.
m
so.. yeah that what is says
f
Do you have more than 1 package.json in ur app with different graphql versions?
ie. mono-repo structure
m
no
BUT I was going down that road. In seed we were using a mono-repo structure. We ended up separating backend from frontend. node_modules might be cached somewhere?
f
I see. If you manually deploy from the SEED console with the force deploy box checked, it’d wipe out the cache and reinstall the node_modules clean.
m
I did to that too. The logs do say skipping cache new lockfile or something like that.
f
I see.. yeah.. Maybe could also try removing the node_modules and the lock file locally; re-installing them; and see if the issue pops up locally
m
Yup did that too
f
damn 😆
m
I was lost that's why I ended looking at the compiled source
I plan on circling back and trying to re-create it with a fresh project
You might notice the error references yarn too. We are not even using yarn. It' hard coded in the source.
f
Yeah I don’t want to waste too much of ur time looking into it. If this pops up again, I’d try spinning up the SEED’s build container locally; clone the code; npm install; and try building it in there.
m
ooohhh. Ok nice.