withastro / astro

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

Multiple relative image paths in md files in content collections create parse failure #8658

Closed phibkro closed 1 year ago

phibkro commented 1 year ago

Astro Info

Astro                    v3.1.2
Node                     v20.7.0
System                   macOS (x64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/vercel
Integrations             @astrojs/sitemap
                         @astrojs/starlight
                         @astrojs/mdx

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

No response

Describe the Bug

Multiple relative image paths in content collection md files create parse failure

When referencing multiple images in 1 md file there is a parse failure, seemingly an unexpected comma added between imports, the imports unable to be parsed. However if referencing only 1 image in an md file there are no problems. The problem only occurs when multiple image references are present.

It seems to be a simple compiling(?) error that adds a comma between image imports and makes the page unbuildable

Error messages

Error message when running npm run dev

 error   Parse failure: Unexpected token (7:64)
  At file: /Users/nori/Desktop/codespace/informatics-notes/src/content/docs/emner/TDT4160/Forelesninger/5. Single-cycle: Interrupts & traps.md
  Contents of line 7:                           import Astro__Z1124s8 from "/src/assets/5.single_cycle.png";,import Astro__Z1i3qpA from "/src/assets/5.risc_v.png";
  File:
    /Users/nori/Desktop/codespace/informatics-notes/src/content/docs/emner/TDT4160/Forelesninger/5. Single-cycle: Interrupts & traps.md?astroPropagatedAssets
  Stacktrace:
Error: Parse failure: Unexpected token (7:64)
At file: /Users/nori/Desktop/codespace/informatics-notes/src/content/docs/emner/TDT4160/Forelesninger/5. Single-cycle: Interrupts & traps.md
Contents of line 7:                             import Astro__Z1124s8 from "/src/assets/5.single_cycle.png";,import Astro__Z1i3qpA from "/src/assets/5.risc_v.png";
    at ssrTransformScript (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/vite/dist/node/chunks/dep-df561101.js:55343:15)
    at ssrTransform (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/vite/dist/node/chunks/dep-df561101.js:55318:12)
    at Object.ssrTransform (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/vite/dist/node/chunks/dep-df561101.js:64992:20)
    at loadAndTransform (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/vite/dist/node/chunks/dep-df561101.js:54989:24)
    at async instantiateModule (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/vite/dist/node/chunks/dep-df561101.js:55875:10)

Error message when running npm run build

Unexpected token (Note that you need plugins to import files that are not JavaScript)
file: /Users/nori/Desktop/codespace/informatics-notes/src/content/docs/emner/TDT4160/Forelesninger/4. Digitallogikk.md:7:68
5:         
6:         import { getImage } from "astro:assets";
7:         import Astro__1bbfnH from "../../../../../assets/1-bit-ALU.png";,import Astro__2lT8Gm from "../../../../../as...
                                                                           ^
8: 
9:         const images = async function() {
The language "pseudo-assembly" doesn't exist, falling back to plaintext.
 error   Unexpected token (Note that you need plugins to import files that are not JavaScript)
  File:
    /Users/nori/Desktop/codespace/informatics-notes/src/content/docs/emner/TDT4160/Forelesninger/4. Digitallogikk.md:7:68
  Code:
    5:         
    6:         import { getImage } from "astro:assets";
    7:         import Astro__1bbfnH from "../../../../../assets/1-bit-ALU.png";,import Astro__2lT8Gm from "../../../../../as...
                                                                               ^
    8: 
    9:         const images = async function() {
  Stacktrace:
RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
    at Module.error (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:13740:16)
    at Module.tryParse (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:14471:25)
    at Module.setSource (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:14072:39)
    at ModuleLoader.addModuleSource (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:24644:20)

  Cause:
SyntaxError: Unexpected token (7:68)
    at pp$4.raise (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:21616:13)
    at pp$9.unexpected (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:18824:8)
    at pp$5.parseExprAtomDefault (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:20985:8)
    at pp$5.parseExprAtom (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:20980:17)
    at pp$5.parseExprSubscripts (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:20764:19)
    at pp$5.parseMaybeUnary (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:20730:17)
    at pp$5.parseExprOps (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:20657:19)
    at pp$5.parseMaybeConditional (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:20640:19)
    at pp$5.parseMaybeAssign (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:20607:19)
    at pp$5.parseExpression (file:///Users/nori/Desktop/codespace/informatics-notes/node_modules/rollup/dist/es/shared/node-entry.js:20570:19)

What's the expected result?

Expected astro to generate multiple image paths without fail

Link to Minimal Reproducible Example

https://github.com/phibkro/astro-starlight-multiple-image-references-bug

Participation

Princesseuh commented 1 year ago

This is fixed already, but is currently unreleased. We'll release it on Monday once we're back to work.

phibkro commented 1 year ago

nice! thanks!