Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Improve @neutrinojs/loader-merge error handling #1075

Closed
edmorley opened this issue Sep 5, 2018 · 1 comment
Closed

Improve @neutrinojs/loader-merge error handling #1075

edmorley opened this issue Sep 5, 2018 · 1 comment
Labels

Comments

@edmorley
Copy link
Member

edmorley commented Sep 5, 2018

Whilst trying out the testcase repo in #1066, I got the following exception:

$ yarn build --inspect-new > build.js

TypeError: Cannot read property 'plugins' of undefined
    at C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\deepmerge\dist\umd.js:63:55
    at Array.forEach (<anonymous>)
    at mergeObject (C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\deepmerge\dist\umd.js:62:25)
    at deepmerge (C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\deepmerge\dist\umd.js:84:16)
    at config.module.rule.use.tap.opts (C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\@neutrinojs\loader-merge\index.js:6:16)
    at Object.tap (C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\webpack-chain\src\Use.js:14:20)
    at C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\@neutrinojs\loader-merge\index.js:6:4
    at Api.use (C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\neutrino\src\api.js:200:7)
    at module.exports (C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\neutrino-preset-emotion\index.js:4:12)
    at Api.use (C:\Users\Ed\src\dfsfdsfsfdsfwfsd\node_modules\neutrino\src\api.js:200:7)

This turned out to be because neutrino-preset-emotion was listed before @neutrinojs/react and so the compile rule that the emotion preset was hoping to modify didn't yet exist:
https://github.com/nwaywood/neutrino-preset-emotion/blob/f538455dafff6310e150aaa113c2f9f0d80dfa5e/index.js#L4-L6

It seems that @neutrinojs/loader-merge should either:

  1. throw will a clearer message if the rule doesn't exist
  2. check that the rule exists first, and if not, then do nothing (though this could hide mistakes)

That said, (1) overlaps with #687 (in that we should probably apply the same fix there to rules as well as plugins), and I've also been wondering if loader-merge is really necessary, since it's adding another layer of abstraction around something that only takes a few lines of webpack-chain usage.

@edmorley
Copy link
Member Author

@neutrinojs/loader-merge was removed in #1182.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

1 participant