-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find module 'astro:content' #5711
Comments
Hey @azan-n! Yes, you’ll need to run a build or use our new |
I have tried this with EDIT: In all cases, I do get a message that reads |
@azan-n hm, and do you see a |
Update: just realized types only generate if there is at least one I also agree this is pretty confusing. Will address with a bug fix 👍 |
No.
I make it a point after every generation command. I realize TS can be a bit slow to catchup.
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.
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 After creating 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! |
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 |
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') Dependencies: "dependencies": { tailwind.config.cjs: module.exports = { 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 |
This was the solution. Thank you! |
@ilievskif Nice! We just baselined all of our betas, so installing |
I'm getting this same issue with Astro 2.1.9 in my 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 |
Hi Ben, thanks for getting back to me! Yeah the I'm able to import Looking inside 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 |
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. Prettier{
"tabWidth": 4,
"printWidth": 100,
"arrowParens": "always",
"proseWrap": "always",
"overrides": [
{
"files": "*.mdx",
"options": {
"printWidth": 80
}
}
]
} Eslint{
"env": {
"browser": true,
"es2021": true,
"jest/globals": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"globals": {
"React": true,
"JSX": true
},
"processor": "disable/disable",
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:astro/recommended",
"airbnb",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:jest/recommended",
"plugin:jest/style",
"prettier"
],
"plugins": ["react", "@typescript-eslint", "import", "jsx-a11y", "jest", "disable", "prettier"],
"rules": {
"import/extensions": 0,
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"react/require-default-props": 0,
"react/function-component-definition": [2, { "namedComponents": "arrow-function" }],
"react/jsx-filename-extension": [2, { "extensions": [".js", ".jsx", ".tsx", ".mdx"] }],
"react/jsx-props-no-spreading": 0
},
"settings": {
"react": {
"version": "detect"
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
}
}
},
"overrides": [
{
"files": ["**/*.mdx"],
"extends": ["plugin:mdx/recommended"],
"settings": {
"mdx/code-blocks": true,
"mdx/language-mapper": {}
}
},
{
// we need to make sure we're not linting js files twice
"files": ["**/*.js", "**/*.jsx"],
"settings": {
"disable/plugins": "@typescript-eslint"
}
},
{
"files": ["*.astro"],
"parser": "astro-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser",
"extraFileExtensions": [".astro"]
}
}
]
} |
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 First removing airbnb, I found installing eslint-import-resolver-typescript fixed any .eslintrc.json{
"env": {
"browser": true,
"es2021": true,
"jest/globals": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"globals": {
"React": true,
"JSX": true
},
"processor": "disable/disable",
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:astro/recommended",
"airbnb",
"airbnb-typescript",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:jest/recommended",
"plugin:jest/style",
"prettier"
],
"plugins": ["react", "@typescript-eslint", "import", "jsx-a11y", "jest", "disable", "prettier"],
"rules": {
"import/extensions": 0,
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"react/require-default-props": 0,
"react/function-component-definition": [2, { "namedComponents": "arrow-function" }],
"react/jsx-filename-extension": [2, { "extensions": [".js", ".jsx", ".tsx", ".mdx"] }],
"react/jsx-props-no-spreading": 0
},
"settings": {
"react": {
"version": "detect"
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
}
}
},
"overrides": [
{
"files": ["**/*.mdx"],
"extends": ["plugin:mdx/recommended"],
"settings": {
"mdx/code-blocks": true,
"mdx/language-mapper": {}
}
},
{
"files": ["**/*.js", "**/*.jsx"],
"settings": {
"disable/plugins": "@typescript-eslint"
}
},
{
"files": ["*.astro"],
"parser": "astro-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser",
"extraFileExtensions": [".astro"]
}
}
]
} package.json{
"dependencies": {
"@astrojs/markdoc": "^0.1.2",
"@astrojs/mdx": "^0.19.1",
"astro": "^2.4.1",
"eslint-config-airbnb": "^19.0.4",
"kleur": "^4.1.5",
"react": "^18.2.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"eslint": "^8.40.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-airbnb": "0.0.1-security",
"eslint-plugin-astro": "^0.27.0",
"eslint-plugin-disable": "^2.0.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-mdx": "^2.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"jest": "^29.5.0",
"typescript": "^5.0.4"
}
} Hope this helps! |
Closing since this issue hasn't seen any replies. Seems reported issues with |
This is an issue again with Astro 2.7:
|
@lloydjatkinson can you open a new issue with a repro? Thanks! |
I just solved the issue by adding module declaration for 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 OR
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 |
In my case I put the wrong name in the folder, instead of putting |
In my case the error |
yes for me also...thank you :) |
Runing |
@SotaNoniwa good fix 🚀 |
Nvm, I've found the reason: |
I have the same error, driving me up the wall, tried all of the above, oddly my site builds just fine. https://github.com/rdthree/astro-rd3-sketchbook/blob/master/src/content/config.ts |
Adding the following line to
|
Why do we have to do all this nonsense? Moreover, the problem is not fixed! It is a disaster to produce patch solutions without knowing what the problem is. |
Fyi to anyone who stumbles here from google search'n, I had to change this in my tsconfig file to get typescript happy:
|
@WillDelish hm, relaxing typescript settings shouldn't be a requirement for using |
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
The text was updated successfully, but these errors were encountered: