naxodev / oss

Open Source Software (OSS) projects by naxodev
https://naxo.dev
MIT License
19 stars 1 forks source link

[nx-cloudflare] Publish command not working for a fresh project #38

Closed mnlbox closed 5 months ago

mnlbox commented 5 months ago

Current Behavior

When I run my project through the publish command I'm getting this error in my terminal:

 NX   Cannot find configuration for task api-test:publish

Pass --verbose to see the stacktrace.

Expected Behavior

It's just a helloworld application based on Hono. Do I missed anything in my wrangler.toml file? What should I do to fix this and deploy and publish my worker? Maybe a more clear error message can be helpful here.

GitHub Repo

No response

Steps to Reproduce

  1. Create my project with this command:

    pnpm nx generate @naxodev/nx-cloudflare:application --name api-test--template hono --directory apis/test --port 4001 --projectNameAndRootFormat=as-provided
  2. Then run my project with this command:

    pnpm nx publish api-test

I can run my project sucessfully but I'm getting this error on publish:

NX   Cannot find configuration for task api-test:publish

Pass --verbose to see the stacktrace.

Nx Report

NX   Report complete - copy this into the issue template

Node   : 20.11.0
OS     : linux-arm64
pnpm   : 8.15.5

nx                 : 18.2.4
@nx/js             : 18.2.4
@nx/jest           : 18.2.4
@nx/linter         : 18.2.4
@nx/eslint         : 18.2.4
@nx/workspace      : 18.2.4
@nx/devkit         : 18.2.4
@nx/esbuild        : 18.2.4
@nx/eslint-plugin  : 18.2.4
@nx/nest           : 18.2.4
@nx/node           : 18.2.4
@nx/playwright     : 18.2.4
@nx/react          : 18.2.4
@nrwl/tao          : 18.2.4
@nx/vite           : 18.2.4
@nx/web            : 18.2.4
@nx/webpack        : 18.2.4
typescript         : 5.4.4
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/vite/plugin
@nx/playwright/plugin
---------------------------------------
Community plugins:
@naxodev/nx-cloudflare : 2.0.1

Failure Logs

No response

Operating System

Additional Information

I'm using vscode devContainer with a Debian based linux in a MacOs host machine.

NachoVazquez commented 5 months ago

Thank you! I'll check this one in the evening.

NachoVazquez commented 5 months ago

Yes, it is one of the supported arguments.

export interface DeployExecutorSchema {
  name: string;
  noBundle: boolean;
  env: string;
  outdir: string;
  compatibilityDate: string;
  compatibilityFlags: string[];
  latest: boolean;
  assets: string;
  site: string;
  siteInclude: string[];
  siteExclude: string[];
  var: string[];
  define: string[];
  triggers: string[];
  routes: string[];
  tsconfig: string;
  minify: boolean;
  nodeCompat: boolean;
  dryRun: boolean;
  keepVars: boolean;
}
NachoVazquez commented 5 months ago

I understand the problem.

publish and deploy are aliases, but only for the executor. For example:

      "executor": "@naxodev/nx-cloudflare:deploy"

is the same as

      "executor": "@naxodev/nx-cloudflare:publish"

however, we are generating the applications with deploy as the command name, which is causing the confussion

    "deploy": {
      "executor": "@naxodev/nx-cloudflare:deploy"
    }

so the options here are either change the docs to use deploy or change the generator to use publish

NachoVazquez commented 5 months ago

Since wrangler publish has been deprecated, I will move everything to deploy. But you can use it right now.

mnlbox commented 5 months ago

@NachoVazquez Thanks for the update, I tried this command: pnpm nx deploy api-test. And this is the output:

> nx run api-test:deploy

 ⛅️ wrangler 3.49.0
-------------------
▲ [WARNING] Using the latest version of the Workers runtime. To silence this warning, please choose a specific version of the runtime with --compatibility-date, or add a compatibility_date to your wrangler.toml.

✘ [ERROR] In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.

🪵  Logs were written to "/home/node/.config/.wrangler/logs/wrangler-2024-04-11_13-43-49_985.log"

————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target deploy for project api-test (3s)

   ✖  1/1 failed
   ✔  0/1 succeeded [0 read from cache]

So I think it will work after setting the CLOUDFLARE_API_KEY. I'll check with API_KEY and will inform you here.

mnlbox commented 5 months ago

@NachoVazquez the deploy command also seems working but it return the below warning:

pnpm nx run service-test:deploy

> nx run service-test:deploy

 ⛅️ wrangler 3.50.0 (update available 3.51.0)
-------------------------------------------------------
▲ [WARNING] Using the latest version of the Workers runtime. To silence this warning, please choose a specific version of the runtime with --compatibility-date, or add a compatibility_date to your wrangler.toml.

✘ [ERROR] In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.

🪵  Logs were written to "/home/node/.config/.wrangler/logs/wrangler-2024-04-17_07-14-51_645.log"

———————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target deploy for project service-test (3s)

   ✖  1/1 failed
   ✔  0/1 succeeded [0 read from cache]

I think maybe a bit more information and guide or a "how to deploy" section in README is also useful. But I'm new in CloudFlare so I guess by some research I can do it.

NachoVazquez commented 5 months ago

You need to set the Cloudflare API key in your env variables. I might make a note on the docs. However, this is needed for any Cloudflare project beyond this plugin.