cli icon indicating copy to clipboard operation
cli copied to clipboard

[Bug] `calibre site create-deploy` failing on syntax error

Open omgaz opened this issue 1 year ago • 1 comments

Describe the bug

Hiya 👋🏻

We're getting a failure on the latest npm release of the calibre cli, v5.2.0 with the graphql-request module that was upgraded last week via https://github.com/calibreapp/cli/pull/719

import { OperationTypeNode } from 'graphql';
         ^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'OperationTypeNode' not found. The requested module 'graphql' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'graphql';
const { OperationTypeNode } = pkg;

Can reproduce locally using:

npm install [email protected] --save
npx calibre site create-deploy

We're using NodeJS v18.16.1 with NPM v9.5.1, locally and in GitHub actions Ubuntu runners.

Run npm install calibre --save && npx calibre site create-deploy --site=$CALIBRE_SITE_SLUG --revision=$GITHUB_SHA --repository https://github.com/$GITHUB_REPOSITORY

Rolling back to npm install [email protected] --save works as a work-around.

Thanks, Gaz

CLI Installation Method

npm

CLI Version

5.2.0

What’s your operating system?

Mac

How To Reproduce

Locally on a mac:

npm install [email protected] --save
npx calibre site create-deploy

in Github actions as:

name: Calibre

on:
  workflow_call:
    secrets:
      CALIBRE_API_TOKEN:
        required: true
      CALIBRE_SITE_SLUG:
        required: true

permissions:
  contents: read

jobs:
  calibre:
    name: Calibre
    runs-on: ubuntu-latest
    timeout-minutes: 4
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version-file: '.nvmrc'
          cache: 'npm'
      - name: Calibre Deploy
        run: |
          npm install calibre --save && npx calibre site create-deploy --site=$CALIBRE_SITE_SLUG --revision=$GITHUB_SHA --repository https://github.com/$GITHUB_REPOSITORY
        env:
          CALIBRE_API_TOKEN: ${{ secrets.CALIBRE_API_TOKEN }}
          CALIBRE_SITE_SLUG: ${{ secrets.CALIBRE_SITE_SLUG }}
          GITHUB_SHA: ${{ github.sha }}
          GITHUB_REPOSITORY: ${{ github.event.repository.name }}

Relevant Log Output

import { OperationTypeNode } from 'graphql';
         ^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'OperationTypeNode' not found. The requested module 'graphql' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'graphql';
const { OperationTypeNode } = pkg;

Screenshots

Screenshot 2024-09-04 at 14 37 04

Code of Conduct

  • [X] I agree to follow this project’s Code of Conduct

omgaz avatar Sep 04 '24 04:09 omgaz

Hey @omgaz, thanks for logging this, appreciate it.

I tried replicating this issue with the same node version, but wasn't able to. Looking at the errors it seems like its relating to CommonJS support.

Am I correct in thinking that your project is using CommonJS rather than ESM?

benschwarz avatar Sep 16 '24 05:09 benschwarz

I created a commonjs example to see if cjs support was broken in 5.2.0, but it works as expected.

{
  "name": "test-cjs-app",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "calibre": "5.2.0"
  }
}

const calibre = require("calibre");

const listTestLocations = async () => {
  const locations = await calibre.Agent.list();

  console.log(locations);
};

listTestLocations();

The example outputs agent locations as expected. At the moment I'm unable to replicate this issue, despite having taken a couple of test attempts. There haven't been other reports of this issue to date, so I will for now assume that it was a blip and will close the issue as a result.

@omgaz, at the moment I don't have a clear case on why this issue occurred for you, please do let me know if you're still experiencing this!

benschwarz avatar Oct 24 '24 04:10 benschwarz

Hi Ben, apologies for not getting back. I'll reach out when I have a moment. Thanks for looking into this again.

omgaz avatar Oct 24 '24 04:10 omgaz