Skip to content

[Bug]: runtime's source.source() does not return a string #7781

@theninthsky

Description

@theninthsky

System Info

System:
OS: Windows 11 10.0.22631
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 8.69 GB / 15.79 GB
Binaries:
Node: 20.11.1 - C:\Program Files\nodejs\node.EXE
npm: 10.8.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (127.0.2651.74)
Internet Explorer: 11.0.22621.3527
npmPackages:
@rspack/cli: ^1.0.0 => 1.0.0
@rspack/core: ^1.0.0 => 1.0.0
@rspack/plugin-react-refresh: ^1.0.0 => 1.0.0

Details

When extracting the chunk sources in the build using source.source(), all sources are extracted as strings except for the runtime chunk, which returns the following object: {"type":"Buffer","data":[...]

Relevant code snippet:

new HtmlPlugin({
        scriptLoading: 'module',
        templateContent: ({ compilation }) => {
          const assets = compilation.getAssets()
          const pages = pagesManifest.map(({ chunk, path, title, data }) => {
            const scripts = assets
              .map(({ name }) => name)
              .filter(name => new RegExp(`[/.]${chunk}\\.(.+)\\.js$`).test(name))

            return { path, title, scripts, data }
          })

          if (production) {
            const assetsWithSource = assets
              .filter(({ name }) => /^scripts\/.+\.js$/.test(name))
              .map(({ name, source }) => ({
                url: `/${name}`,
  ----------->  source: source.source(),
                parentPaths: pages.filter(({ scripts }) => scripts.includes(name)).map(({ path }) => path)
              }))

            writeFileSync(join(__dirname, 'public', 'assets.js'), JSON.stringify(assetsWithSource))
          }

          return htmlTemplate(pages)
        }
      }),

Reproduce link

https://github.com/theninthsky/client-side-rendering/tree/rspack

Reproduce Steps

  1. Clone https://github.com/theninthsky/client-side-rendering.git
  2. Switch to the rspack branch.
  3. npm i
  4. In the scripts/inject-worker-html.js file, comment line 29 which removes the helper file public/assets.js.
  5. npm run build
  6. Open public/assets.js and look for runtime.

You'll see that only this chunk was extracted as an object.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions