Cannot build my first Python project with Wrangler

Hello,

Sorry for the very beginner question. I was following the documentation but I got stuck. I’m trying to build and deploy a Worker hello world based on Python to my site.

I installed wrangler with npm. After that I had to install the “transcrypt” module for Python (this is not mentioned in the docs).

Then I created the project with

wrangler generate mytest https://github.com/cloudflare/python-worker-hello-world

Then I went to the wrangler.toml file and set the account_id field.

First question: I’m supposed to set the zone_id too. Where is the zone id? I couldn’t find it anywhere.

I then ran:

wrangler preview --watch

and it failed with

Module not found: Error: Can't resolve './__target__index.js' in 'D:\Development\mytest'

resolve ‘./__target__index.js’ in ‘D:\Development\mytest’
using description file: D:\Development\mytest\package.json (relative path: .)
Field ‘browser’ doesn’t contain a valid alias configuration
using description file: D:\Development\mytest\package.json (relative path: ./__target__index.js)
no extension
Field ‘browser’ doesn’t contain a valid alias configuration
D:\Development\mytest__target__index.js doesn’t exist
.wasm
Field ‘browser’ doesn’t contain a valid alias configuration
D:\Development\mytest__target__index.js.wasm doesn’t exist
.mjs
Field ‘browser’ doesn’t contain a valid alias configuration
D:\Development\mytest__target__index.js.mjs doesn’t exist
.js
Field ‘browser’ doesn’t contain a valid alias configuration
D:\Development\mytest__target__index.js.js doesn’t exist
.json
Field ‘browser’ doesn’t contain a valid alias configuration
D:\Development\mytest__target__index.js.json doesn’t exist
as directory
D:\Development\mytest__target__index.js doesn’t exist

I don’t know how to continue after this… :frowning:

I had the same problem, you need to use WSL for Windows and install Python, Transcrypt and Wrangler on that. Or use a Linux system

If you have a site on Cloudflare you should be able to see zone id on the overview tab.

There’s many guides on installing wsl on Windows, here’s one from google (https://www.omgubuntu.co.uk/how-to-install-wsl2-on-windows-10)

This is very much worth doing, not just for this issue.

Thanks for the reply.
I don’t have a site yet, I’ve just signed up for free to check out how Workers work. This is my URL: https://curly-cell-d3ca.gcsaba2.workers.dev/ It doesn’t have a zone as far as I see. Screenshot: https://imgur.com/i42DlMK

Writing that Worker with Javascript in the browser was pretty easy. I’d like to do it now offline in Python.

You can use

workers_dev = true

in your wrangler.toml file to do this without a site.

I tried installing wrangler on my centos7 system and it failed with the following:

$ sudo npm i @cloudflare/wrangler -g
/usr/bin/wrangler -> /usr/lib/node_modules/@cloudflare/wrangler/run-wrangler.js

> @cloudflare/[email protected] postinstall /usr/lib/node_modules/@cloudflare/wrangler
> node ./install-wrangler.js

/usr/lib/node_modules/@cloudflare/wrangler/node_modules/mkdirp/index.js:91
                    throw err0;
                    ^

Error: EACCES: permission denied, mkdir '/root/.wrangler'
    at Object.mkdirSync (fs.js:921:3)
    at Function.sync (/usr/lib/node_modules/@cloudflare/wrangler/node_modules/mkdirp/index.js:72:13)
    at Binary._getInstallDirectory (/usr/lib/node_modules/@cloudflare/wrangler/node_modules/binary-in         stall/src/binary.js:49:14)
    at Binary.install (/usr/lib/node_modules/@cloudflare/wrangler/node_modules/binary-install/src/bin         ary.js:75:22)
    at install (/usr/lib/node_modules/@cloudflare/wrangler/binary.js:44:10)
    at Object.<anonymous> (/usr/lib/node_modules/@cloudflare/wrangler/install-wrangler.js:4:1)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14) {
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path: '/root/.wrangler'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @cloudflare/[email protected] postinstall: `node ./install-wrangler.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @cloudflare/[email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

It looks like it’s trying to access /root/.wrangler, which doesn’t exist. So I create it. After that, it fails with

Error: EACCES: permission denied, mkdir '/root/.wrangler/bin'

So I made the .wrangler dir have 777 permissions. After this, it looks like it succeeded, but I still wonder why I had to do this .wrangler magic in /root.

# npm i @cloudflare/wrangler -g
/usr/bin/wrangler -> /usr/lib/node_modules/@cloudflare/wrangler/run-wrangler.js

> @cloudflare/[email protected] postinstall /usr/lib/node_modules/@cloudflare/wrangler
> node ./install-wrangler.js

Downloading release https://workers.cloudflare.com/get-npm-wrangler-binary/1.10.3/x86_64-unknown-linux-musl
wrangler has been installed!
+ @cloudflare/[email protected]
added 34 packages from 21 contributors in 6.341s

But then I go:
$ wrangler generate mytest https://github.com/cloudflare/python-worker-hello-world

/usr/lib/node_modules/@cloudflare/wrangler/node_modules/binary-install/src/binary.js:60
      throw `You have not installed ${this.name ? this.name : "this package"}`;
      ^
You have not installed wrangler
(Use `node --trace-uncaught ...` to show where the exception was thrown

Nevermind, I npm installed without the -g flag and then it worked.

I wrote “wrangler preview --watch” and looks like it’s working \o/

you shouldn’t need sudo for npm either.

The README for the python worker hello world https://github.com/cloudflare/python-worker-hello-world includes links on how to get transcrypt working on Windows without WSL. If there’s a way to make the README clearer, PRs are welcome.

npm install @cloudflare/wrangler -g --unsafe-perm=true --allow-root works!!