withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
44.08k stars 2.29k forks source link

tutorial [tag].astro code is error #11411

Closed View-my-Git-Lab-krafi closed 4 days ago

View-my-Git-Lab-krafi commented 4 days ago

Astro Info

Astro v4.11.0
Node v20.14.0
System Windows (x64)st-fontend-1> npx astro info
Package Manager npm
Output static
Adapter none
Integrations none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

---
import BaseLayout from '../../layouts/BaseLayout.astro';
import BlogPost from '../../components/BlogPost.astro';

export async function getStaticPaths() {
   // 'getStaticPaths' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.ts(7023)
  const allPosts = await Astro.glob('../posts/*.md');
  //'allPosts' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
  const uniqueTags = [...new Set(allPosts.map((post) => post.frontmatter.tags).flat())];
// 'uniqueTags' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
//'uniqueTags' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)  
return uniqueTags.map((tag) => {
    const filteredPosts = allPosts.filter((post) => post.frontmatter.tags.includes(tag));
    //Parameter 'post' implicitly has an 'any' type.ts(7006)
    return {
      params: { tag },
      props: { posts: filteredPosts },
    };
  });
}

const { tag } = Astro.params;
const { posts } = Astro.props;
---
<BaseLayout pageTitle={tag}>
  <p>Posts tagged with {tag}</p>
  <ul>
    {posts.map((post) => <BlogPost url={post.url} title={post.frontmatter.title}/>)}
    //Parameter 'post' implicitly has an 'any' type.ts(7006)
  </ul>
</BaseLayout>

What's the expected result?

as you can see i comment out those error from vscode , if i try to build i will face the same, issue. i will see same error. the tags feature i made on my real project is not working i decided to follow tutorial again , but i end up with same error again. i was trying to configure with netlify .

and i write my astro.config.mjs


import { defineConfig } from 'astro/config';

import netlify from "@astrojs/netlify";

//if you are using localhost PC
export default defineConfig({}); 

//If you are using netlify
//export default defineConfig({ output: "server", adapter: netlify() });

I dont know can i write it to use in both way one real [tag].astro and tags/index.astro i solve those error , but when i try to run with netlify it didnt work those feature became broken,

if you dont have time to think so solve or see this issue please give me some demo theme that have tags feature and also used with netlify

Link to Minimal Reproducible Example

https://gitlab.com/krafi/astro-fast-fontend-1

Participation

View-my-Git-Lab-krafi commented 4 days ago

one more thing import BlogPost from '../../components/BlogPost.astro'; file code is missing on astro doc tutorial

ematipico commented 4 days ago

The typescript errors come from your tsconfig.json, where you decided to use the astro/tsconfigs/strict preset. If you wish to not have typescript errors, you should the astro/tsconfigs/base preset.

View-my-Git-Lab-krafi commented 4 days ago

The typescript errors come from your tsconfig.json, where you decided to use the astro/tsconfigs/strict preset. If you wish to not have typescript errors, you should the astro/tsconfigs/base preset.

i see, it remove all the error on vscode, but when i go to build


PS C:\Users\krafi\Desktop\web\astro-fast-fontend-1> npx astro build
16:03:17 [types] Added src/env.d.ts type declarations.
16:03:17 [vite] Re-optimizing dependencies because vite config has changed
16:03:17 [build] output: "static"
16:03:17 [build] directory: C:\Users\krafi\Desktop\web\astro-fast-fontend-1\dist\
16:03:17 [build] Collecting build info...
16:03:17 [build] ✓ Completed in 102ms.
16:03:17 [build] Building static entrypoints...
16:03:17 [types] Added src/env.d.ts type declarations.
16:03:18 [ERROR] [vite] x Build failed in 706ms
Unexpected "const"
  Stack trace:
    at failureErrorWithLog (C:\Users\krafi\Desktop\web\astro-fast-fontend-1\node_modules\esbuild\lib\main.js:1472:15)
    at responseCallbacks.<computed> (C:\Users\krafi\Desktop\web\astro-fast-fontend-1\node_modules\esbuild\lib\main.js:622:9)
    at Socket.readFromStdout (C:\Users\krafi\Desktop\web\astro-fast-fontend-1\node_modules\esbuild\lib\main.js:600:7)
    at addChunk (node:internal/streams/readable:559:12)
    at Readable.push (node:internal/streams/readable:390:5)
View-my-Git-Lab-krafi commented 4 days ago

here is the brunch after i tried to do experiment with astro/tsconfigs/base https://gitlab.com/krafi/astro-fast-fontend-1/-/tree/astro_tsconfigs_strict_typesafety?ref_type=heads created another build error issue for this https://github.com/withastro/astro/issues/11416

last successful brunch with tag broken https://gitlab.com/krafi/astro-fast-fontend-1/-/tree/last_sucessfulbrunch_with_tag_broken

View-my-Git-Lab-krafi commented 3 days ago

forget about the last comment i figure out the issue , https://gitlab.com/krafi/astro-fast-fontend-1/-/tree/bd4c5beee9a92060dd6935220e34b88dbdf1a55d

so, in my theme tag feature work perfectly when astro.config.mjs is

import { defineConfig } from 'astro/config';

//if you are using localhost PC
export default defineConfig({}); 

when when i change it to the netlify things


import { defineConfig } from 'astro/config';

import netlify from "@astrojs/netlify";

//If you are using netlify
export default defineConfig({ output: "server", adapter: netlify() });

and run it as localhost dev i got error on the [tags].astro feature if you need to read that file https://gitlab.com/krafi/astro-fast-fontend-1/-/blob/bd4c5beee9a92060dd6935220e34b88dbdf1a55d/src/pages/tags/%5Btag%5D.astro Cannot read properties of undefined (reading 'map')

if i sent that netlify config i just see a blank page when i open the tags feature.