[Custom Functions] Cannot find module 'graphql-tag'

Hello everybody,

I have been trying to deploy a simple webhook function.

// 8base.yml

functions:
  testFn:
    type: webhook
    handler:
      code: src/webhooks/testFn/handler.js
    path: /testFn
    method: POST

The handler.js file calls the grapqhql-tag library:

import gql from “graphql-tag”;

The graphql-tag library is installed in the package.json file:

// package.json

{
  "name": ".",
  "version": "1.0.0",
  "description": "8base Custom Logic",
  "dependencies": {
    "graphql": "^15.3.0",
    "graphql-request": "^1.6.0",
    "graphql-tag": "^2.11.0",
    "path": "^0.12.7"
  }
}

When I invoke the function locally with 8base invoke-local testFn -m request it works fine.

However, after deploying the function (using 8base deploy), invoking the function on the server with the command 8base invoke testFn -m request displays the following error message:

// Result of the function invoked on the server

Result:
{
  "data": {
    "testFn": null
  },
  "errors": [
    {
      "message": "Cannot find module 'graphql-tag'",
      "locations": [
        {
          "line": 2,
          "column": 5
        }
      ],
      "path": [
        "invoke"
      ],
      "code": "MODULE_NOT_FOUND"
    }
  ]
}

I have tried the same using node.js syntax const gql = require("graphql-tag") and it returns the same error.

Also, I have tried to use relative paths instead, but their also return a similar result.

// Does not work

import gql from "./node_modules/graphql-tag"

// Doesn't work either

const gql = require("./node_modules/graphql-tag")

I am super embarrassed because it looks like a small issue, however, I haven’t found any working solution to this issue.

What am I missing ? Could somehow help me figure that out please?

Regards,
Andréas

1 Like

Hey @andreas!

Is this still giving you trouble? Please share your project directory structure when you have a chance…

const gql = require(‘graphql-tag’);

is working great for me in my function.

1 Like

I solved it thanks to @ilya.8base !

The package name "." was causing the issue.

Changing the name solved the issue. :white_check_mark:

Note: Since the name “.” is given by default, this issue is very likely to occur again. Maybe we could change the default name? What do you think?

1 Like

Where is that package?,im trying to find it, but I don’t

We were referring to this :point_down:

1 Like