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:
- Configure webpack using a configuration
webpack.config.ts
, including using Typescript syntax and types. - Install
ts-node
in the project - Install
tsm
in the project, because you want to use esbuild to transpile your scripts and webpack configuration, not ts-node. - run the compilation with
node -r tsm $(yarn bin webpack)
There will be type errors, because the following happens:
tsm
is registered as a require hook forts
filests-node
is additionally registered as a require hook forts
files, which I didn't ask for and don't want- The webpack configuration is correctly transpiled to JS by tsm/esbuild
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
Done #3329