workers-sdk
workers-sdk copied to clipboard
🐛 BUG: Wrangler not honouring CLOUDFLARE_ACCOUNT_ID environment variable when cached config is here
What version of Wrangler are you using?
2.0.23
What operating system are you using?
Linux
Describe the Bug
Hello :smiley:
When trying to publish the same directory to 2 different accounts, I get auth errors when I don't clean "cached" config:
Simulating a publish to abc account id:
$ cat ../node_modules/.cache/wrangler/wrangler-account.json
{ "account": { "id": "abc", "name": "" } }
When running wrangler with def account id given as environment variable:
$ CLOUDFLARE_ACCOUNT_ID=def CLOUDFLARE_API_TOKEN=ghi npx wrangler pages publish . --project-name=jkl --branch=mno
Retrieving cached values for account from ../node_modules/.cache/wrangler
▲ [WARNING] Warning: Your working directory is a git repo and has uncommitted changes
To silence this warning, pass in --commit-dirty=true
✘ [ERROR] A request to the Cloudflare API (/accounts/abc/pages/projects/jkl/upload-token) failed.
Authentication error [code: 10000]
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/wrangler2/issues/new/choose
I suppose environment variable should override "cached" config? (if not and you consider it "by design", feel free to close this issue)
In particular, according to me, the error line ✘ [ERROR] A request to the Cloudflare API (/accounts/abc/pages/projects/jkl/upload-token) failed. should not use account abc but def given in CLOUDFLARE_ACCOUNT_ID.
Demo
I highlighted this behaviour with a CircleCI workflow:
version: 2.1
jobs:
config:
docker:
- image: cimg/node:18.4.0
steps:
- run:
name: "Publish to cloudflare pages (KO)"
command: |
npm i [email protected]
mkdir public
cd public
echo "Hello config" >> index.html
mkdir -p ../node_modules/.cache/wrangler/
echo '{ "account": { "id": "abcdefghijklmnopqrstuvwxyz", "name": "" } }' > ../node_modules/.cache/wrangler/wrangler-account.json
CLOUDFLARE_ACCOUNT_ID=d97aaabbbcccdddaaabbbccc93a054 npx wrangler pages publish . --project-name=honour-account-id-env --branch=config
noconfig:
docker:
- image: cimg/node:18.4.0
steps:
- run:
name: "Publish to cloudflare pages (OK)"
command: |
npm i [email protected]
mkdir public
cd public
echo "Hello noconfig" >> index.html
CLOUDFLARE_ACCOUNT_ID=d97aaabbbcccdddaaabbbccc93a054 npx wrangler pages publish . --project-name=honour-account-id-env --branch=noconfig
workflows:
release_noconfig:
jobs:
- noconfig:
filters:
branches:
only: /^main$/
release_config:
jobs:
- config:
filters:
branches:
only: /^main$/
Failing with cached config

Publish without config

Related?
- #1422
- #1585