webpack/webpack-cli

no way to prevent interpret from transpiling the config, even if another tool has been configured

hedgepigdaniel opened this issue · 2 comments

It's nice that interpret is used to allow configuration to be written in ES/TS/etc without configuration. However, it is not always desired that a loader hook is automatically registered, and sometimes it can cause a bug.

I think it should be configurable, just as --config-register can be used to register additional hooks, it should be possible to turn off the use of interpret.

What is the current behavior?

When using a configuration with one of the matched filetypes, for example webpack.config.ts, node-interpret registers a loader (e.g. ts-node to be used to transpile the configuration. There is no way to prevent this behaviour except uninstalling the loader (for example uninstalling ts-node. But this is virtually impossible in a larger project - since usually something else will depend on ts-node and cause it to be installed.

To Reproduce

Steps to reproduce the behavior:

  1. Configure webpack using a configuration webpack.config.ts, including using Typescript syntax and types.
  2. Install ts-node in the project
  3. Install tsm in the project, because you want to use esbuild to transpile your scripts and webpack configuration, not ts-node.
  4. run the compilation with node -r tsm $(yarn bin webpack)

There will be type errors, because the following happens:

  1. tsm is registered as a require hook for ts files
  2. ts-node is additionally registered as a require hook for ts files, which I didn't ask for and don't want
  3. The webpack configuration is correctly transpiled to JS by tsm/esbuild
  4. ts-node is incorrectly used to transpile the configuration, but at this point it has already been transpiled. By default, there will be type errors and the compilation will fail. As suggested in webpack/webpack#13844 (comment), you can work around this by configuring ts-node to skip type checking, but it should not have been used in the first place!

Expected behavior

It should be possible to turn off the use of interpret, so that it does not conflict with the user's intended strategy for transpiling scripts and configuration.

PR welcome, should not be hard