Skip to content

Cannot use JSX in custom template #373

@liorgreenb

Description

@liorgreenb

🐛 Bug Report

When using custom template, JSX syntax usage results in "Unexpected token"

To Reproduce

  1. Create custom template using JSX syntax for exmaple:
function template(
    { template },
    opts,
    { imports, componentName, props, jsx, exports },
) {
    return template.ast`
${imports}
function ${componentName}(${props}) {
return <div>${jsx}</div>
}
${exports}
`
}
  1. Use the template in the config

Expected behavior

Expected babel to transpile the JSX and continue successfully.

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

Paste the results here:

## System:
 - OS: macOS Mojave 10.14.5
 - CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
 - Memory: 505.64 MB / 16.00 GB
 - Shell: 3.2.57 - /bin/bash
## Binaries:
 - Node: 8.10.0 - /usr/local/bin/node
 - Yarn: 1.17.3 - /usr/local/bin/yarn
 - npm: 6.13.2 - /usr/local/bin/npm
## npmPackages:
 - @svgr/webpack: 5.0.0 => 5.0.0 

Thanks (:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions