For Workers & Pages, what is the name of the domain?
https://falling-hall-643e.pages.dev/
What is the error message?
[ERROR] TypeError: Cannot read properties of undefined (reading ‘env’)
What is the issue or error you’re encountering
When I run wrangler pages dev I have this error. I suspect I have the same on deploy but I just don’t see this error. At least I have Internal Server Error from the API endpoint.
What steps have you taken to resolve the issue?
There’s more detailed investigation process with steps of reproducing.
Repo for recreating issues of Cloudflare + Wrangler integrations for monorepo with Nuxt Layers DDD architecture
Also, I prepared a similar repo but without Nuxt 3 layers architecture to exclude a guessing that it happens because of layers:
Nuxt 3 + Nitro + Cloudflare Wrangler + Database D1 + Drizzle ORM issue
This repo was prepared by following the guide from the Cloudflare Docs:
What are the steps to reproduce the issue?
See the link above
Screenshot of the error
The issue caused because of strict path to directory where the wrangler.json
file has to be generated in Nitro.
I prepare a PR to the Nitro directory with the detailed explanation what it solves:
v3
← serhii-chernenko:feat/wrangler-generation-dir
opened 09:41PM - 23 Mar 25 UTC
### 🔗 Linked issue
https://github.com/nitrojs/nitro-cloudflare-dev/issues/57
…
### ❓ Type of change
- [x] 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
- [x] 🐞 Bug fix (a non-breaking change that fixes an issue)
- [x] 👌 Enhancement (improving an existing functionality like performance)
### 📚 Description
- Related repo with issues:
- Monorepo with Nuxt layers: https://github.com/serhii-chernenko/nuxt-layers-cloudflare?tab=readme-ov-file
- Nuxt app: https://github.com/serhii-chernenko/falling-hall-643e?tab=readme-ov-file
- Fix PR: https://github.com/serhii-chernenko/falling-hall-643e/pull/1
- URL to preview: https://falling-hall-643e.pages.dev
The main issue is in destination of auto-generated `wrangler.json` file that available only in:
```bash
dist/_worker.js/wrangler.json
```
It could be automatically found for the commands like:
```bash
npx wrangler pages dev
npx wrangler pages deploy
```
But it could NOT be found for the command:
```
npx wrangler d1 migrations apply falling-hall-643e
```

There are no errors, but also there are no any actions as well.
To fix it, I have to specify `wrangler.json` file path:
```
npx wrangler d1 migrations apply falling-hall-643e -c dist/_worker.js/wrangler.json
```

But as you can see on the screen, it generates the state to
```
./dist/_worker.js/.wrangler/state/v3/d1
```
instead of
```
.wrangler/state/v3/d1
```
So, to make it working, I have to manually move it to the root dir
```
rm -rf .wrangler/state
mv dist/_worker.js/.wrangler/state .wrangler
```
I also tried to set the state path via `persistDir`
```ts
// nuxt.config.ts
nitro: {
cloudflareDev: {
configPath: 'dist/_worker.js/wrangler.json',
persistDir: 'dist/_worker.js/.wrangler/state/v3', // this one
},
},
```
But it's not the option, because the `dist` directory is recreated every time and I lose my state.
At least, I already know the nature of the recent issues.
I'd suggest a solution for the Nitro repository:
Allow to specify `wrangler.json` path where it has to be generated. Not where it's located for `cloudflareDev` in the repository of [`nitro-cloudflare-dev`](https://github.com/nitrojs/nitro-cloudflare-dev/):
```ts
nitro: {
preset: 'cloudflare-pages',
cloudflare: {
deployConfigPath: './' // it will be the root directory by default, no need to specify
}
}
```
Because currently it depends on `serverDir`:
https://github.com/nitrojs/nitro/blob/v3/src/presets/cloudflare/utils.ts#L253C1-L254C71
```ts
const wranglerConfigDir = nitro.options.output.serverDir;
const wranglerConfigPath = join(wranglerConfigDir, "wrangler.json");
```
That's a reason why I created this PR.
It allows to specify a nitro root dir as a directory where the `wrangler.json` file has to be located. It avoids usage of custom option `-c dist/_worker.js/wrangler.json` for commands `npx wrangler`.
And, it solves the issue of saving state in the right root directory that won't be wiped every time on build.
### 📝 Checklist
- [x] I have linked an issue or discussion.
system
Closed
March 25, 2025, 9:56pm
3
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.