Shopify / shopify-api-js

Shopify Admin API Library for Node. Accelerate development with support for authentication, graphql proxy, webhooks
MIT License
944 stars 394 forks source link

unable to deploy firebase function when importing v3.0.1 or later #388

Closed zachsitka closed 1 year ago

zachsitka commented 2 years ago

Issue summary

When you import the @shopify/shopify-api package into a node firebase function, it will fail to deploy with the following error: Error: SQLITE_CANTOPEN: unable to open database file

Expected behavior

You should be able to deploy using this package.

Actual behavior

When you deploy code that imports the @shopify/shopify-api package in a firebase function to the cloud, the function fails to deploy at the point where the function is invoked to make sure that it is properly deployed. When this happens, the function crashes with the error Error: SQLITE_CANTOPEN: unable to open database file.

This happens when using versions 3.0.1 or above. 3.0.0 is not affected and deploys fine.

Error: Process exited with code 16 at process. (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:92:22) at process.emit (node:events:390:28) at process.emit (node:domain:475:12) at process.exit (node:internal/process/per_thread:184:15) at sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:44:9) at process. (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:84:44) at process.emit (node:events:402:35) at process.emit (node:domain:475:12) at process._fatalException (node:internal/process/execution:164:25)

The error seems to have something to do with files not being found.

Steps to reproduce the problem

  1. Create a firebase function (https://firebase.google.com/docs/functions/get-started)
  2. Deploy the function to the cloud and verify that the function works
  3. Now import the @shopify/shopify-api package into your function and use it in some way
  4. Deploy the function to the cloud -- function will fail to deploy
  5. Downgrade your @shopify/shopify-api package to 3.0.0
  6. Deploy the function to the cloud and it will succeed

Reduced test case


Checklist

renyuanz commented 2 years ago

same issue here: https://github.com/Shopify/shopify-node-api/issues/389

@surma please revert the changes of v3.1.0 that making SQLite a peer-deps of session storage (https://github.com/Shopify/shopify-node-api/blob/main/src/context.ts#L46)

cpsoinos commented 2 years ago

Receiving a similar issue when attempting to deploy to AWS Lambda via Serverless Framework after upgrading from 3.0.1 to 3.1.0:

⠹ Packaging (0s)
✘ [ERROR] Could not resolve "mock-aws-s3"

    ../../node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:28:
      43 │     const AWSMock = require('mock-aws-s3');
         ╵                             ~~~~~~~~~~~~~

  You can mark the path "mock-aws-s3" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

✘ [ERROR] Could not resolve "nock"

    ../../node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:112:23:
      112 │   const nock = require('nock');
          ╵                        ~~~~~~

  You can mark the path "nock" as external to exclude it from the bundle, which will remove this
  error. You can also surround this "require" call with a try/catch block to handle this failure at
  run-time instead of bundle-time.

✘ [ERROR] Could not resolve "pg-native"

    ../../node_modules/pg/lib/native/client.js:4:21:
      4 │ var Native = require('pg-native')
        ╵                      ~~~~~~~~~~~

  You can mark the path "pg-native" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.
surma commented 2 years ago

I’ll look into this.

Can you share with me what Session storage module you are using? Can you find where your code calls Shopify.Context.initialize({...}) and tell me what (if any) value you set for SESSION_STORAGE ?

harishv7 commented 2 years ago

I have the same issue when using AWS Lambda with Serverless Stack framework after upgrading from 3.0.1 to 3.1.0. Same error as above:

✘ [ERROR] Could not resolve "mock-aws-s3"

    node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:28:
      43 │     const AWSMock = require('mock-aws-s3');
         ╵                             ~~~~~~~~~~~~~

  You can mark the path "mock-aws-s3" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

✘ [ERROR] Could not resolve "nock"

    node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:112:23:
      112 │   const nock = require('nock');
          ╵                        ~~~~~~

  You can mark the path "nock" as external to exclude it from the bundle, which will remove this
  error. You can also surround this "require" call with a try/catch block to handle this failure at
  run-time instead of bundle-time.

✘ [ERROR] Could not resolve "pg-native"

    node_modules/pg/lib/native/client.js:4:21:
      4 │ var Native = require('pg-native')
        ╵                      ~~~~~~~~~~~

  You can mark the path "pg-native" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

Appreciate your help on this please

daichi-yamauchi commented 2 years ago

I'm facing same issue with AWS lambda. I'm using custom session storage with dynamo db.

It may be fixed by #393. I'll waiting the release of the pull.

viraths commented 2 years ago

Having exactly same issue with 3.1.3. But I have added those modules as external modules (assuming these are needed on dev only) in lambda bundling and the error is gone. But now I am getting this error

  externalModules: ['aws-sdk', 'mock-aws-s3', 'nock'],
github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] commented 1 year ago

We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!