nwaywood / neutrino-preset-flow

Neutrino preset for flow
3 stars 1 forks source link

Error in neutrino 8.2.1 #1

Closed evliu closed 6 years ago

evliu commented 6 years ago

This happens when I launch the project:

yarn start
yarn run v1.5.1
$ neutrino start

TypeError: Cannot read property 'rules' of undefined
    at neutrino.config.module.rule.use.tap.options (/Users/e/console/node_modules/neutrino-preset-flow/index.js:10:38)
    at Object.tap (/Users/e/console/node_modules/webpack-chain/src/Use.js:12:18)
    at module.exports (/Users/e/console/node_modules/neutrino-preset-flow/index.js:8:10)
    at Api.use (/Users/e/console/node_modules/neutrino/src/api.js:200:7)
    at Api.use (/Users/e/console/node_modules/neutrino/src/api.js:204:12)
    at use (/Users/e/console/node_modules/neutrino/src/api.js:246:27)
    at _map (/Users/e/console/node_modules/ramda/src/internal/_map.js:6:19)
    at map (/Users/e/console/node_modules/ramda/src/map.js:64:14)
    at /Users/e/console/node_modules/ramda/src/internal/_dispatchable.js:41:15
    at f2 (/Users/e/console/node_modules/ramda/src/internal/_curry2.js:29:14)
    at Api.use (/Users/e/console/node_modules/neutrino/src/api.js:246:11)
    at Api.use (/Users/e/console/node_modules/neutrino/src/api.js:204:12)
    at middleware.forEach.middleware (/Users/e/console/node_modules/neutrino/bin/base.js:25:40)
    at Array.forEach (<anonymous>)
    at module.exports (/Users/e/console/node_modules/neutrino/bin/base.js:25:14)
    at module.exports (/Users/e/console/node_modules/neutrino/bin/start.js:8:10)
error An unexpected error occurred: "Command failed.
Exit code: 1
Command: sh
Arguments: -c neutrino start
Directory: /Users/e/console
Output:
".

thoughts? thanks!

evliu commented 6 years ago

got it to work by adding @neutrinojs/eslint and changing the index.js to

const loaderMerge = require('@neutrinojs/loader-merge');
const merge = require('deepmerge');

module.exports = (neutrino, options) => {
    neutrino.config.module
        .rule('lint')
        .use('eslint')
        .tap(({ rules, plugins, baseConfig, ...rest }) => ({
            ...rest,
            rules: merge(rules, { 'flowtype-errors/show-errors': 'error' }),
            plugins: [...plugins, 'flowtype', 'flowtype-errors'],
            baseConfig: { extends: [...baseConfig.extends || [], 'plugin:flowtype/recommended'] }
        }));
    neutrino.use(loaderMerge('compile', 'babel'), {
        presets: ['flow']
    });
};
nwaywood commented 6 years ago

Yes you are right, I just tested it and it seems that eslint is also a dependency, I didn't realise that. I'll update the readme. Thanks :)

evliu commented 6 years ago

The other issue I found is that baseConfig is an empty object which is why I used the || operator

nwaywood commented 6 years ago

You shouldn't need to do that because the flow plugin injects plugin:flowtype/recommended for you. See here https://github.com/nwaywood/neutrino-preset-flow/blob/master/index.js#L17-L19

evliu commented 6 years ago

The issue is actually that baseConfig is empty so there is no extends property, thus it tries to concat on undefined

nwaywood commented 6 years ago

Ah I understand now. Thanks.

I never run into this issue myself because I am using neutrino-preset-prettier-eslint which creates the extends field for prettier.

I just pushed v0.0.4 which should fix your issue https://www.npmjs.com/package/neutrino-preset-flow

Please let me know if that doesn't work

evliu commented 6 years ago

Thanks! It works now except I get a new issue, which I'll make issue #3