Skip to content
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

Astro generates empty .-index.bundle.js (after update to 1.6.8) #5400

Closed
1 task
impcyber opened this issue Nov 14, 2022 · 3 comments · Fixed by #5399
Closed
1 task

Astro generates empty .-index.bundle.js (after update to 1.6.8) #5400

impcyber opened this issue Nov 14, 2022 · 3 comments · Fixed by #5399
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@impcyber
Copy link
Contributor

impcyber commented Nov 14, 2022

What version of astro are you using?

1.6.8

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

Linux

Describe the Bug

Using configuration

vite.build.rollupOptions:
        output: {
          inlineDynamicImports: false,
          chunkFileNames: 'assets/chunks/[name].[hash].js',
          entryFileNames: 'assets/[name].bundle.js',
          assetFileNames: 'assets/[name].bundle.[ext]',
        },

When import css file via js import, a js file with a strange name is generated .-index.bundle.js

without customizing vite.build.rollupOptions.output patterns, the empty .-index.123456.js file is generated.

image

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-xfum8x-ppta8q?file=dist/assets/chunks/.-index.3d9a295b.js

Participation

  • I am willing to submit a pull request for this issue.
@impcyber
Copy link
Contributor Author

impcyber commented Nov 15, 2022

After digging through the code, I found the place where the problem occurred:
https://github.com/withastro/astro/blob/main/packages/astro/src/core/build/css-asset-name.ts#L36

const firstParentId = parents[0]?.[0].id || 'index';

// Use the last two segments, for ex /docs/index
let dir = firstParentId;

if page is not nested, firstParent becomes 'index'

https://github.com/withastro/astro/blob/main/packages/astro/src/core/build/css-asset-name.ts#L43

while (i < 2) {
	if (dir === pagesDir) {
		break;
	}

to compare against pagesDir, dir must be an absolute path

this code solves the problem:

...
  const pagesDir = viteID(new URL("./pages", settings.config.srcDir));
  const indexPage = viteID(new URL("./pages/index", settings.config.srcDir));
...
  const firstParentId = parents[0]?.[0].id || indexPage;

@matthewp
Copy link
Contributor

Thanks @impcyber, can you submit a PR?

@matthewp matthewp added the - P2: nice to have Not breaking anything but nice to have (priority) label Nov 15, 2022
@impcyber
Copy link
Contributor Author

No problem, submitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants