AlexGilleran / jsx-control-statements

Neater If and For for React JSX
https://www.npmjs.com/package/babel-plugin-jsx-control-statements
MIT License
1.62k stars 64 forks source link

Not working with create-react-app #86

Closed Irfanbsse2060 closed 3 years ago

Irfanbsse2060 commented 5 years ago

I am using create-react-app . I have ejected create-react-app using npm run eject.Now i have all the webpack config files. As mentioned in docs i have added this line "plugins": ["jsx-control-statements"] But it doesn't trans pile jsx-control-statement. I am using babel version 7. Is it related to babel version ?

AlexGilleran commented 5 years ago

It should definitely work with Babel 7. What does your .babelrc look like? :man_shrugging:

Irfanbsse2060 commented 5 years ago

Here is my .babelrc `{ "presets": [ "react-app" ], "plugins": [ "jsx-control-statements","@babel/plugin-proposal-export-default-from"]

} `

Here is babel configuration in webpack config file . ` { test: /.(js|mjs|jsx|ts|tsx)$/, include: paths.appSrc, loader: 'babel-loader', options: { customize: require.resolve( 'babel-preset-react-app/webpack-overrides' ),

            plugins: [
              require('babel-plugin-jsx-control-statements'),
              require('@babel/plugin-proposal-export-default-from'),
              [require('@babel/plugin-proposal-decorators'), { legacy: true }],

              [
                require.resolve('babel-plugin-named-asset-import'),
                {
                  loaderMap: {
                    svg: {
                      ReactComponent:
                        '@svgr/webpack?-prettier,-svgo![path]',
                    },
                  },
                },
              ],

            ],
            // This is a feature of `babel-loader` for webpack (not Babel itself).
            // It enables caching results in ./node_modules/.cache/babel-loader/
            // directory for faster rebuilds.
            cacheDirectory: true,
            cacheCompression: isEnvProduction,
            compact: isEnvProduction,
          },
        },`

Here is the error image

AlexGilleran commented 5 years ago

Oh right, those look like eslint errors - you'll have to either use https://github.com/vkbansal/eslint-plugin-jsx-control-statements or turn it off.

zhanghaojincheng commented 5 years ago

I have solved my problem. because eslintconfig

lousongtao commented 5 years ago

could you explain how to config the "eslintConfig" node in package.json after I do eject in a create-react-app project? I read the introduction of https://github.com/vkbansal/eslint-plugin-jsx-control-statements and add all of the information into the node of "eslintConfig", but it always reports "react/jsx-no-undef". Here is my node of "eslintConfig"

"eslintConfig": { "plugins": [ "jsx-control-statements" ], "extends": ["react-app","plugin:jsx-control-statements/recommended"], "rules": { "react/jsx-no-undef": [2, { "allowGlobals": true }], "jsx-control-statements/jsx-choose-not-empty": 1, "jsx-control-statements/jsx-for-require-each": 1, "jsx-control-statements/jsx-for-require-of": 1, "jsx-control-statements/jsx-if-require-condition": 1, "jsx-control-statements/jsx-otherwise-once-last": 1, "jsx-control-statements/jsx-use-if-tag": 1, "jsx-control-statements/jsx-when-require-condition": 1, "jsx-control-statements/jsx-jcs-no-undef": 1, "no-undef": 0 }, "ecmaFeatures": { "jsx": true }, "env": { "jsx-control-statements/jsx-control-statements": true } },

misaeldossantos commented 4 years ago

@lousongtao I deleted node_modules and I re-install all packages, and it worked with that same configuration

texttechne commented 3 years ago

Looks like a configuration issue which has been solved. Closing...