Closed azan-n closed 1 year ago
Hey @azan-n! Yes, youβll need to run a build or use our new sync
command to generate this module. Try running pnpm astro sync
in your terminal.
Try running
pnpm astro sync
in your terminal.
I have tried this with npx
, pnpm
, and pnpx
in separate repos. Regardless, the error does not go away.
EDIT: In all cases, I do get a message that reads [content] Types generated 34ms
@azan-n hm, and do you see a src/content/types.generated.d.ts
file? If not, there might be something else going wrong. You can also quit and restart your editor, or reset the TS language server using the VS Code command palette (cmd + shift + P):
Update: just realized types only generate if there is at least one .md
or .mdx
file inside a collection directory. It won't run on an empty content/
folder! Let me know if adding a file resolves your issue.
I also agree this is pretty confusing. Will address with a bug fix π
do you see a
src/content/types.generated.d.ts
file?
No.
reset the TS language server
I make it a point after every generation command. I realize TS can be a bit slow to catchup.
at least one
.md
or.mdx
file inside a collection directory
In all cases, I have had .md files in nested or the same directory as content/. I have no generated file in it, and the error persists.
I also agree this is pretty confusing. Will address with a bug fix π
Thanks so much for the support. I've had quite some time on my badge writing documentation. I'd love to help with it if required.
I got the same msg Cannot find module 'astro:content' or its corresponding type declarations.ts(2307)
.
After creating hello-world.md
inside content/blog/
, and trying reset TS language server after that I try running npx astro sync
, all problem gone.
Don't forget configuring schema and collection entry. Thanks π
@rizkysaskiaputra Ah yes, I think an empty config file will block type gen as well. I think relaxing the error detection on collection files before generating types would be helpful. Good to know that works for you though!
@rizkysaskiaputra Ah yes, I think an empty config file will block type gen as well. I think relaxing the error detection on collection files before generating types would be helpful. Good to know that works for you though!
My config file has been complete with schema declarations and the import statement. I just updated to 1.9.2 and still face the same issue.
EDIT: Updated to 2.0.0-beta.2. It works now. Thanks so much.
So glad to hear that @azan-n! To anyone following the thread, you'll find future content collections improvements on the 2.0 beta branch. Install in your projects with npm i astro@beta
. If you have the MDX integration, bump with npm i @astrojs/mdx@beta
as well.
Hello, I'm getting a postCSS / @astrojs/tailwind error when I update this existing project to astro@beta & @astrojs/mdx@beta
Does @astrojs/tailwind 2.1.3 need to be updated too?
error Cannot read properties of undefined (reading 'postcss') File: /Users/.../node_modules/@astrojs/tailwind/dist/index.js:78:22 Code: 77 | const tailwindConfig = (userConfig == null ? void 0 : userConfig.value) ?? getDefaultTailwindConfig(config.srcDir);
78 | config.style.postcss.plugins.push(tailwindPlugin(tailwindConfig)); | ^ 79 | config.style.postcss.plugins.push(autoprefixerPlugin); 80 | if (applyBaseStyles) { 81 | injectScript("page-ssr",
import '@astrojs/tailwind/base.css';
); Stacktrace: TypeError: Cannot read properties of undefined (reading 'postcss')
Dependencies:
"dependencies": { "@astrojs/markdown-remark": "^1.2.0", "@astrojs/mdx": "^1.0.0-beta.2", "@astrojs/rss": "^2.0.0", "@astrojs/sitemap": "^1.0.0", "@astrojs/tailwind": "^2.1.3", "@astropub/md": "^0.1.4", "astro": "^2.0.0-beta.4", "tailwindcss": "^3.2.4" }, "devDependencies": { "@tailwindcss/typography": "^0.5.9" }
tailwind.config.cjs:
module.exports = { content: ['./src/*/.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], theme: { extend: {}, }, plugins: [ require('@tailwindcss/typography'), ], }
Note: build and sync + having a mdx file in /content/mycollection didn't fix the missing 'astro:content' module.
Thanks.
@natguy Ah yes, you'll need to install @astrojs/tailwind@beta
as well. We've introduced a small breaking changes to the integration internals. Happy to share we are baselining our betas today though, so you'll be free to install @latest
soon enough π
@natguy Ah yes, you'll need to install
@astrojs/tailwind@beta
as well. We've introduced a small breaking changes to the integration internals. Happy to share we are baselining our betas today though, so you'll be free to install@latest
soon enough π
This was the solution. Thank you!
@ilievskif Nice! We just baselined all of our betas, so installing @latest
for Astro core and the Tailwind integration should do the trick too π
I'm getting this same issue with Astro 2.1.9 in my src/content/config.ts
file.
The code runs fine but I get an error from eslint/no-unresolved, is there specific way Eslint should be configured? I couldn't spot anything in the docs or examples.
@MerlinMason Interesting, there shouldn't be anything else to configure here. I assume you tried running astro sync
or astro dev
to generate the astro:content
module?
Hi Ben, thanks for getting back to me!
Yeah the .astro/types.d.ts
file exists, I'm running my dev server with astro check --watch & astro dev
. There's also a src/env.d.ts
which references the generated types. Regenerating the types with astro sync
doesn't seem to make a difference.
I'm able to import astro:content
into my .astro
pages and the linter is happy, but importing into rss.xml.js
or config.ts
and it complains.
Looking inside .astro/types.d.ts
I can see the following module has been declared 10 times (is that expected?)
declare module 'astro:content' {
interface Render {
'.mdx': Promise<{
Content: import('astro').MarkdownInstance<{}>['Content'];
headings: import('astro').MarkdownHeading[];
remarkPluginFrontmatter: Record<string, any>;
}>;
}
}
And then there's a few other type definitions, but nothing else that mentions astro:content
.
Got it, thanks for confirming @MerlinMason. And that definitely shouldn't be declared 10 times! π I'll look into that separately.
And admittedly... it sounds like everything is wired up correctly for you. I'm wondering if there's some eslint rule that's conflicting here. Can you send your eslint and prettier configs to be sure?
Hi Ben, apologies for the huge delay here, I've been away on holiday and just catching up with messages - thanks again for looking into this!
Here's my config files, apologies the Eslint config is slightly long.
This issue should be reopened, its still happening unfortunately π€·
@johny Curious if you have a repro different from Merlin's above? This should be handled with the fixes outlined above, so I have a feeling we're fixing edge cases now
@MerlinMason Late reply incoming! I poked around your setup, and I found eslint-config-airbnb
and the import
plugin were causing the issue.
First removing airbnb, I found installing eslint-import-resolver-typescript fixed any import/nounresolved
errors. Trying to add airbnb back, a bit of Googling brought me to eslint-config-airbnb-typescript. Here's my final eslint and dependencies:
Hope this helps!
Closing since this issue hasn't seen any replies. Seems reported issues with astro:content
are linter-specific. Feel free to respond to my messages above as we debug @MerlinMason!
This is an issue again with Astro 2.7:
FAIL src/domain/article-query.spec.ts [ src/domain/article-query.spec.ts ]
FAIL src/domain/book-query.spec.ts [ src/domain/book-query.spec.ts ]
FAIL src/domain/note-query.spec.ts [ src/domain/note-query.spec.ts ]
Error: Failed to load url astro:content (resolved id: astro:content) in /workspace/lloydatkinson.net/src/domain/types.ts. Does the file exist?
@lloydjatkinson can you open a new issue with a repro? Thanks!
I just solved the issue by adding module declaration for .astro
files in src/env.d.ts
declare module '*.astro'
If you are getting this error while deploying to Cloudflare Pages (SSG), you can resolve it with 2 options:
Either your change your build command to npx astro sync && npm run build
on Cloudflare's dashboard (very easy solution)
OR
You generate the types locally by running the sync command locally npx astro sync
and then commit / push the generated tsconfig.tsbuildinfo
file to your repo. You only need to do this, if you change your .md / .mdx schema. Finally, you might have this file listed on your .gitignore file so be careful.
Edit: the second solution is not working, my bad...
I had the same problem, command "npm run astro check" worked for me.
Had the same problem and npm run build
then restarting TS server is what worked for me. π
In my case I put the wrong name in the folder, instead of putting /content
I put /contents
π...This took me 30 minutes lol
In my case the error TS2307: Cannot find module Β astro:content
showed in a blank Astro project. I had to run npm run dev
and afterwards my WebStorm 2023.2.2 was able to find the type definitions for Astro. π
npm run astro check
yes for me also...thank you :)
Runing npx astro sync
then close VSCode and restart it again resolved mine.
@SotaNoniwa good fix π
Hi all, I'm facing this issue in Astro v4.3.2, is there a workaround or solution for that issue?
I've followed all your comments mentioned above a none of them have helped to me :(
Nvm, I've found the reason:
don't put content/blog
folder inside pages/
It should be src/content/blog
What version of
astro
are you using?1.8.0
Are you using an SSR adapter? If so, which one?
No
What package manager are you using?
npm, pnpm
What operating system are you using?
macOS 13
Describe the Bug
I have been eagerly waiting for even a beta of the Content Collections RFC to start shipping my blog. Thanks to @bholmesdev I got a chance much earlier than I could expect. I upgraded from 1.6.4(?) to 1.8.0 but I got the TS error
Cannot find module 'astro:content' or its corresponding type declarations.ts(2307)
when trying to import thedefineCollection
function.Steps to reproduce
pnpm create astro@latest
ornpm create astro@latest
import { defineCollection, z } from "astro:content"
within the 'config.ts'Continuing with this state of the application leads to no errors during the build or in the dev server.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-j2falm?file=content/config.ts
Participation