web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
10.19k stars 577 forks source link

[Bug]: Issue with fork-ts-checker-webpack-plugin not picking up new code #8364

Open lukemurray opened 3 weeks ago

lukemurray commented 3 weeks ago

System Info

System: OS: macOS 15.1 CPU: (10) arm64 Apple M1 Max Memory: 3.81 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.17.0 - /opt/homebrew/opt/node@20/bin/node npm: 10.8.2 - /opt/homebrew/opt/node@20/bin/npm Browsers: Chrome: 130.0.6723.92 Safari: 18.1

Details

Hi, I'm looking at moving from webpack to rsbuild which uses Rspack.

Everything is working so except our type generation. We use GraphQL and we use Apollo client to generate Typescript types for the queries etc.

With webpack we used compiler.hooks.make.tap to just call the apollo client:codegen command to generate the types. This worked fine.

Bringing things over to rsbuild/pack we have a Rspack plugin that does the same hook. The hook is called and the types are generated. However when fork-ts-checker-webpack-plugin runs it is like it only has the old generated type files as they were when the process started. If we restart the npx rsbuild dev process it will pick up the new type changes.

I can confirm that the types are being generated, I can change a query and open the generated file to see the change. VS Code picks the change up and correctly reports on any issues. Just rspack seems to have some cache of the file from the start of running the process.

Any ideas?

Reproduce link

No response

Reproduce Steps

Run npx rsbuild dev

With this plugin

export class GenerateTypesPlugin {
  apply(compiler) {
    compiler.hooks.beforeCompile.tapPromise('GenerateTypesPlugin', async () => { // or hooks.make
      logger.log('Generating GraphQL types...')
      const errors = await regenerateTypes()
      if (errors.length > 0) {
        logger.error('Errors occurred during type generation:')
        errors.forEach((err) => {
          logger.error(err)
        })
      } else logger.log('Done.')
    })
  }
}

regenerateTypes will call Apollo, but basically it generates .ts files which we import in our components.

github-actions[bot] commented 21 hours ago

Hello @lukemurray, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.