Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel-plugin-add-jsx-attribute: Property name expected type of string but got undefined #773

Open
mikeriley131 opened this issue Sep 14, 2022 · 1 comment
Labels

Comments

@mikeriley131
Copy link

🐛 Bug Report

Before adding and using the the babel-plugin-add-jsx-attribute, everything built correctly, but when I try implementing this plugin I get the following error.

.../node_modules/@svgr/cli/dist/index.js:373
    throw error;
    ^

TypeError: /Users/e6ss3/Sites/balance/packages/balance-icons/assets/AlertCircle.svg: Property name expected type of string but got undefined
    at Object.validate (.../node_modules/@babel/core/node_modules/@babel/types/lib/definitions/utils.js:159:13)
    at validateField (.../node_modules/@babel/core/node_modules/@babel/types/lib/validators/validate.js:24:9)
    at validate (.../node_modules/@babel/core/node_modules/@babel/types/lib/validators/validate.js:17:3)
    at validateNode (.../node_modules/@babel/core/node_modules/@babel/types/lib/builders/validateNode.js:16:27)
    at Object.jsxIdentifier (.../node_modules/@babel/core/node_modules/@babel/types/lib/builders/generated/index.js:1535:36)
    at getAttribute (.../node_modules/@svgr/babel-plugin-add-jsx-attribute/dist/index.js:32:47)
    at .../node_modules/@svgr/babel-plugin-add-jsx-attribute/dist/index.js:49:32
    at Array.forEach (<anonymous>)
    at PluginPass.JSXOpeningElement (.../node_modules/@svgr/babel-plugin-add-jsx-attribute/dist/index.js:41:25)
    at newFn (.../node_modules/@babel/core/node_modules/@babel/traverse/lib/visitors.js:181:21) {
  code: 'BABEL_TRANSFORM_ERROR'
}
error Command failed with exit code 1.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.svg$/i,
        issuer: /\.[jt]sx?$/,
        use: ['@svgr/webpack'],
      },
    ],
  },
};

.svgrrc.js

module.exports = {
  icon: true,
  ref: true,
  replaceAttrValues: {
    '#111': 'currentColor',
  },
  jsx: {
    babelConfig: {
      plugins: [
        [
          '@svgr/babel-plugin-add-jsx-attribute',
          {
            elements: ['svg'],
            attributes: [
              {
                'aria-hidden': true,
              },
            ],
          },
        ],
      ],
    },
  },
};

To Reproduce

Run svgr -d src assets.

Expected behavior

SVG components build without error with the aria-hidden attribute added to the SVG element.

Run npx envinfo --system --binaries --npmPackages @svgr/core,@svgr/cli,@svgr/webpack,@svgr/rollup --markdown --clipboard

Paste the results here:

## System:
- OS: macOS 12.5.1
- CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
- Memory: 76.76 MB / 16.00 GB
- Shell: 5.8.1 - /bin/zsh
## Binaries:
- Node: 14.17.4 - ~/.nvm/versions/node/v14.17.4/bin/node
- Yarn: 1.22.19 - ~/.yarn/bin/yarn
- npm: 6.14.14 - ~/.nvm/versions/node/v14.17.4/bin/npm
@stale
Copy link

stale bot commented May 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant