Issue
I'm running into a problem, where I have a GraphQL project depending on a service project, when I deploy and execute a query I get prompted with MODULE_NOT_FOUND
on the service package. We use a mono-repository with Lerna and yarn.
To debug my package I ran the following command
sls package
Which will create a .serverless
folder containing the ZIP archive to upload to AWS.
Inside the archive, the folder node_modules is present with the expected service package. Yet when I try to run my application with the following, I get the same error as what's happening in my app sync query panel in AWS
> node dist/lambda.js
Error: Cannot find module '@coin-miles/some-service/src/models'
Require stack:
...
From the AppSync, the error looks like the following
"message": "Error: Cannot find module '@coin-miles/common-service/src/models'\nRequire
stack:\n- /var/task/node_modules/@coin-miles/some-service/dist/entities/some-bag.js\n-
/var/task/node_modules/@coin-miles/some-service/dist/entities/index.js\n-
/var/task/node_modules/@coin-miles/some-service/dist/index.js\n-
/var/task/dist/lambda.js\n- /var/runtime/UserFunction.js\n- /var/runtime/Runtime.js\n-
/var/runtime/index.js"
There are many configuration files, let me know if you have any requests for specific files. Why is my AppSync logging that the package is not present when it is?
some-graphql
\_ node_modules
\_ @coin-miles/some-service
\_ @coin-miles/service-common
\_ dist
\_ lambda.js
My serverless.yml includes the following
service: some-graphql
plugins:
- serverless-plugin-monorepo
- serverless-plugin-common-excludes
- serverless-plugin-include-dependencies
package:
excludeDevDependencies: false
... censored information ...
functions:
resolver:
handler: dist/lambda.handler
Everywhere I look online, there's a lot of mention about npm install
in each dependency repository, then a build, before forming the package, but that didn't solve my problem, as the files are there, but seems to no be referenced...
Solution
After looking at the error for a while, I and my coworker found the culprit. It's quite embarrassing, but the issue was the import statement.
It was hard to see through my question, but in our project, the compiled javascript goes into a dist
folder and the typescript code is in a src
folder. When you do an import, you need to make it for the dist
folder, if you make it from the src
folder, your project will compile and will run the tests, but once you export it, it won't find the javascript.
// Unacceptable
import { BaseService } from "@coin-miles/service-common/src/service";
// Correct answer
import { BaseService } from "@coin-miles/service-common/dist/service";
Answered By - MathieuAuclair
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.