1

I'm following this tutorial (to get cloudflare pages working with fauna db), but when I get to the chapter "Testing and deploying the Worker" and try to run wrangler dev (which will run npm run build, which in turn runs worktop build index.js) I get the error message sh: worktop: command not found.

I have double checked that I have followed each step correctly, checked if worktop was present in the node_modules directory (it is) and also tried to install worktop globally (didn't work).

What am I missing here?

Full output of running wrangler dev:

$ wrangler dev     
  Running npm run build

> fauna-demo-workers@1.0.0 build /Users/me/dev/fauna-demo-workers
> worktop build index.js

sh: worktop: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! fauna-demo-workers@1.0.0 build: `worktop build index.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the fauna-demo-workers@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2022-01-09T12_54_24_718Z-debug.log
Error: Build failed! Status Code: 1
Terrabythia
  • 2,031
  • 3
  • 19
  • 29
  • `tried to install worktop globally (didn't work).` Were there any errors? There shouldn't be any problem installing it globally – Luca Kiebel Jan 09 '22 at 13:10
  • No, it installed fine, but the error stayed the same. Also I running `worktop` from the command line (wherever, since it should be available globally) gave the same error `worktop: command not found`. – Terrabythia Jan 09 '22 at 13:11

1 Answers1

2

you have to install the worktop.build package. That's where the worktop binary comes from. The package called “worktop” is just a runtime library. Not everyone will want to use its opinionated CLI/builder, hence the separate package.

(I'm the author of worktop & worktop.build)

lukeed
  • 409
  • 2
  • 5
  • 13
  • Thanks! When installing `worktop.build` package I can no indeed use the `worktop` command. Still no luck running `worktop build index.js` as in the Faunadb tutorial, but maybe that's the tutorial's fault. – Terrabythia Jan 10 '22 at 20:24
  • The `worktop build index.js` isn't meant to be run directly. You run it by running `wrangler dev`, which in turn invokes `npm run build` as you note. I don't think the tutorial instructs you to run `worktop build index.js` anywhere; please correct me if I'm wrong. (I'm a maintainer of the tutorial). – Rob S. Jan 10 '22 at 20:40
  • 1
    Correct. The tutorial sets up a `"build"` npm script (inside the `package.json` file), which is linked via the `wrangler.toml` file's configuration. Its `build.command` is assigned to `npm run build`, which Wrangler will run during development and as part of `wrangler publish`. – lukeed Jan 10 '22 at 20:47