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

Is it possible to have the template file written in TypeScript? #979

Open
grifotv opened this issue Nov 11, 2024 · 0 comments
Open

Is it possible to have the template file written in TypeScript? #979

grifotv opened this issue Nov 11, 2024 · 0 comments

Comments

@grifotv
Copy link

grifotv commented Nov 11, 2024

💬 Questions and Help

I'd like to have my template file written in TypeScript, like the default template.

I tried creating my own template with the .ts extension:

import { Template } from '@svgr/babel-plugin-transform-svg-component';

const template: Template = (variables, { tpl }) => {

  return tpl`
    //my template
`;
};

module.exports = template;

However, I got the following error when trying to run the command:

import { Template } from '@svgr/babel-plugin-transform-svg-component';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1281:20)
    at Module._compile (node:internal/modules/cjs/loader:1321:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)

It also fails when I try to add my own types rather than importing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant