Closed xino1010 closed 3 months ago
You should run pnpm astro sync
.
You should run
pnpm astro sync
.
should it be the expected behaviour? or astro could be generate types file automatically on dev mode?
Yes dev should run sync under the hood so there may be a bug, I'll have a look
I think the issue lies here https://github.com/withastro/astro/blob/main/packages/astro/src/core/sync/index.ts#L87. If there are no content collections, the env sync code may not be run. @xino1010 do you want to try fixing it?
Ah yeah, that's because sync
was originally meant for content collections. Now we are change its semantics, so we should remove that check at this point, or add an OR check for astro:env
I think the issue lies here https://github.com/withastro/astro/blob/main/packages/astro/src/core/sync/index.ts#L87. If there are no content collections, the env sync code may not be run. @xino1010 do you want to try fixing it?
No sorry, it exceed of my knowledge
@florian-lefebvre I'm happy to submit a PR for this if that's ok?
@Trombach sure do it! Feel free to reach out on Discord in #contribute
if you need help
I get this too, they are simply undefined, I use "astro": "^4.14.4"
.
yarn dev
, yarn sync
, yarn build
all of them fail.
username@computer3:~/Desktop/nemanjam.github.io$ yarn sync
yarn run v1.22.22
$ astro sync
8:47:02 AM [vite] Pre-transform error: Failed to load url astro:env/client (resolved id: astro:env/client) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
8:47:02 AM [vite] Pre-transform error: Failed to load url astro:env/server (resolved id: astro:env/server) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
username@computer3:~/Desktop/nemanjam.github.io$ yarn build
yarn run v1.22.22
$ astro build
8:47:08 AM [vite] Pre-transform error: Failed to load url astro:env/client (resolved id: astro:env/client) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
8:47:08 AM [vite] Pre-transform error: Failed to load url astro:env/server (resolved id: astro:env/server) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
8:47:08 AM [vite] Pre-transform error: Failed to load url @/schemas/config (resolved id: @/schemas/config) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
username@computer3:~/Desktop/nemanjam.github.io$ yarn dev
yarn run v1.22.22
$ astro dev
8:45:00 AM [vite] Pre-transform error: Failed to load url astro:env/client (resolved id: astro:env/client) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
8:45:00 AM [vite] Pre-transform error: Failed to load url astro:env/server (resolved id: astro:env/server) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
8:45:00 AM [vite] Pre-transform error: Failed to load url @/schemas/config (resolved id: @/schemas/config) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
8:45:00 AM [vite] Pre-transform error: Failed to load url @/utils/log (resolved id: @/utils/log) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
8:45:00 AM [vite] Pre-transform error: Failed to load url @/utils/validation (resolved id: @/utils/validation) in /home/username/Desktop/nemanjam.github.io/src/config.ts. Does the file exist?
8:45:00 AM [vite] Error when evaluating SSR module /src/config.ts: failed to import "astro:env/client"
|- Error: Cannot find module 'astro:env/client' imported from '/home/username/Desktop/nemanjam.github.io/src/config.ts'
at nodeImport (file:///home/username/Desktop/nemanjam.github.io/node_modules/vite/dist/node/chunks/dep-BzOvws4Y.js:52945:19)
at ssrImport (file:///home/username/Desktop/nemanjam.github.io/node_modules/vite/dist/node/chunks/dep-BzOvws4Y.js:52812:22)
at eval (/home/username/Desktop/nemanjam.github.io/src/config.ts:3:50)
at instantiateModule (file:///home/username/Desktop/nemanjam.github.io/node_modules/vite/dist/node/chunks/dep-BzOvws4Y.js:52870:11)
@nemanjam 👋 Can you open a new issue? Thank you!
Here it is:
Astro Info
Using last experimental type-safe environment variables features, types are not generated automatically in development mode.
Cannot find module 'astro:env/server' or its corresponding type declarations.ts(2307)
I have to execute
to remove the ts error.
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Code works but intellisense show an error.
Looking the file
env.d.ts
new line is added but the file is not generated under
.astro
folder.Same happens for backend vars.
but if you execute
npm run build
, the error dissapears because typings file is generated.What's the expected result?
Generate automatically
env.d.ts
file on develoment mode.Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-ey4hsq?file=.env
Participation