-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[writing plugin] SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' #12468
Comments
Hey @budarin! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
|
Thanks! |
I'm sorry, but it did not help I added |
have added const core = require('@babel/core');
const t = require('@babel/types');
const template = require('@babel/template');
const jsx = require('@babel/plugin-syntax-jsx').default;
module.exports = () => ({
name: 'my-plugin',
inherits: jsx,
manipulateOptions: (opts, parserOpts) => {
console.log('manipulateOptions'.toUpperCase(), parserOpts);
},
... have log MANIPULATEOPTIONS {
sourceType: 'module',
sourceFileName: '.../projects/my-component/babel-plugin/my-plugin.js',
plugins: [ 'jsx' ]
} jsx plugin is in plugins option SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (2:30)
1 | (
> 2 | ({children, ...rest}) => <Component {...rest}>{children}</Component>;
| ^
3 | ) |
What is the name of the file containing |
@nicolo-ribaudo |
You need to create one of the templates in the plugin like this, to enable JSX in that template: const getResult = template.expression({ plugins: ['jsx'] })`
({children, ...restProps}) => <Component {...restProps} PARAMS>{children}</Component>
`; Also, you need to inherit from Then there is an error about |
thanks a lot! |
I have rewritten the plugin with ERROR in ./src/components/button2.tsx 7:6
Module parse failed: Unexpected token (7:6)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| children: children,
| ...rest
> }) => <Component {...rest} size="l" view="action" width="max">{children}</Component>;
@ ./src/index.tsx 14:0-47 24:36-43 I can't understand what this error is about - plugin generates right code: import { Button, withSizeM, withViewAction, withWidthMax } from '@yandex/ui/Button/desktop';
import { compose } from '@bem-react/core';
const Component = compose(withSizeM, withViewAction, withWidthMax)(Button);
export const Button2 = ({ children: children, ...rest }) => (
<Component {...rest} size="m" view="action" width="max">
{children}
</Component>
); here is transform result with import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
var _jsxFileName = ".../projects/bem-like-component/babel-plugin/__tests__/__fixtures__/output.js";
import { Button, withSizeM, withViewAction, withWidthMax } from '@yandex/ui/Button/desktop';
import { compose } from '@bem-react/core';
const Component = compose(withSizeM, withViewAction, withWidthMax)(Button);
export const Button2 = ({
children: children,
...rest
}) => /*#__PURE__*/_jsxDEV(Component, { ...rest,
size: "m",
view: "action",
width: "max",
children: children
}, void 0, false, {
fileName: _jsxFileName,
lineNumber: 5,
columnNumber: 5
}, this); I don't understand what I should to do with this and this error please, have a look at |
If you add {
type: 'Identifier',
name: '<Component {...restProps} size="l" view="action" width="max">{children}</Component>'
} You need to pass an AST node to |
I've rewritten code with
but still have the error in browser:
|
Oh you also need to delete const result = getResult({
JSX: t.jsxElement(
t.jsxOpeningElement(t.jsxIdentifier("Component"), attributes),
t.jsxClosingElement(t.jsxIdentifier("Component")),
[t.jsxExpressionContainer(t.identifier("children"))]
),
}); |
thanks for the reply and reduced code I've commented
|
I believe it has been fixed in #12479, please update |
I try to install packages with |
it might be incorrect cache! |
Bug Report
Current behavior
Write simple plugin as described in doc, but get the error
Input Code
Expected behavior
success transpilation
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
babel.config.js
Environment
Additional context
Here is the repo. Use
next
branchThe text was updated successfully, but these errors were encountered: