-
Notifications
You must be signed in to change notification settings - Fork 230
Improve error message when using .tap() on undefined plugin #125
Comments
I could definitely see how this would be an issue. Technically this issue can arise from not using neutrino.config.plugin('copy'); This is due to the way the Using these methods creates an entry with that name, and then expects it to be defined. Obviously in the case of conditional plugins, this creates a problem. We do specifically state in the docs about the conditional nature of the plugins: https://neutrino.js.org/packages/web/#plugins
But I agree the error messaging could be better in this scenario. This would have to be done in webpack-chain. |
Yeah I agree this is not expected to work - it's the clearer error message that this issue is about :-) |
Previously if `.tap()` was called for a plugin that didn't exist, the `.tap()` call would succeed, but the `.toConfig()` would fail later with: `TypeError: Cannot read property '__expression' of undefined` This scenario can typically occur when trying to customise a plugin added by a previous preset (where the preset only sometimes adds the plugin, such as in development), and forgetting to add a conditional using `.has()` before calling `.tap()`. Whilst #270 changes that exception to a slightly more useful error message, it is still only shown at the time of the `.toConfig()`, where it's much harder to debug the cause. Now the `.tap()` call itself will show the error: `Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('foo').use(<Plugin>) first` Whilst this error check does technically break the (unlikely) scenario of calling `.tap()` in a preset before the plugin is defined, that ordering was already broken, since the `.tap()`'s args would have been overwritten by the subsequent preset. Fixes #125.
Previously if `.tap()` was called for a plugin that didn't exist, the `.tap()` call would succeed, but the `.toConfig()` would fail later with: `TypeError: Cannot read property '__expression' of undefined` This scenario can typically occur when trying to customise a plugin added by a previous preset (where the preset only sometimes adds the plugin, such as in development), and forgetting to add a conditional using `.has()` before calling `.tap()`. Whilst #270 changes that exception to a slightly more useful error message, it is still only shown at the time of the `.toConfig()`, where it's much harder to debug the cause. Now the `.tap()` call itself will show the error: `Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('foo').use(<Plugin>) first` Whilst this error check does technically break the (unlikely) scenario of calling `.tap()` in a preset before the plugin is defined, that ordering was already broken, since the `.tap()`'s args would have been overwritten by the subsequent preset. Fixes #125.
Previously if `.tap()` was called for a plugin that didn't exist, the `.tap()` call would succeed, but the `.toConfig()` would fail later with: `TypeError: Cannot read property '__expression' of undefined` This scenario can typically occur when trying to customise a plugin added by a previous preset (where the preset only sometimes adds the plugin, such as in development), and forgetting to add a conditional using `.has()` before calling `.tap()`. Whilst #270 changes that exception to a slightly more useful error message, it is still only shown at the time of the `.toConfig()`, where it's much harder to debug the cause. Now the `.tap()` call itself will show the error: `Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('foo').use(<Plugin>) first` Whilst this error check does technically break the (unlikely) scenario of calling `.tap()` in a preset before the plugin is defined by a later preset, that ordering was already broken, since the `.tap()`'s args would have been overwritten by the subsequent preset. Fixes #125.
STR:
yarn add neutrino@8.0.18 @neutrinojs/web@8.0.18
mkdir src
touch contribute.json src/index.js
.neutrinorc.js
containing:yarn start
Expected:
Error message that makes the mistake clear. eg:
Error: Plugin 'copy' is not defined
(along with a stack trace that points to the correct line in
.neutrinorc.js
)Actual:
webpack-chain gives an error message that is hard to track back to a root cause (unclear error message and does not reference a specific line in
.neutrinorc.js
):The root cause here is that the
copy
plugin is only defined whencommand === 'build'
, and so there is no such plugin to.tap()
during yarn start.The text was updated successfully, but these errors were encountered: