question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running with mobx decorator got error

See original GitHub issue

Error messages are as follows:

SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (20:0)

...

 at Object._raise (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:816:17)
    at Object.raiseWithData (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:809:17)
    at Object.expectOnePlugin (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:9920:18)
    at Object.parseDecorator (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:12727:10)
    at Object.parseDecorators (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:12709:30)
    at Object.parseStatement (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:12542:12)
    at Object.parseBlockOrModuleBlockBody (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:13134:25)
    at Object.parseBlockBody (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:13125:10)
    at Object.parseProgram (.../node_modules/@trivago/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:12468:10)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
juanrgmcommented, Nov 18, 2021

The solution to support both decorator plugins it was to support none by default, but with the new option added (importOrderParserPlugins) you can override that default config, no?

Now prettier, without prettier-plugin-sort-imports, can successfully format the next code:

function test(constructor: Function) {}
@test
class A {}

But if you install prettier-plugin-sort-imports:

[error] src\index.ts: SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (5:0)

Adding the plugins to importOrderParserPlugins fixes the issue, but was it mandatory requirement delete the default plugins?

0reactions
byaracommented, Dec 14, 2021

Hey @fangwei18 and @juanrgm, sorry that you are facing this issue. As you know, we were adding few babel parser plugins by default in version 2, legacy-decorator, typescript and jsx. The issue is there are other proposals for decorators and passing 2 parser plugins to babel for the decorators is not possible. Therefore we decided to let the user decides what parser to pass. To solve the issue, you should create a . prettierrc file and pass proper importOrderParserPlugins value. I’m going to close the issue, but if you have other problems with the plugin, feel free to open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to install MobX but getting decorators error when start ...
When I install Mobx and Mobx react I am getting the following error. ./src/index.js Error: The 'decorators' plugin requires a ...
Read more >
Enabling decorators · MobX
When migrating from MobX 4/5 to 6, we recommend to always run the code-mod, to make sure the necessary makeObservable calls are generated....
Read more >
mobx-undecorate - npm
mobx -undecorate. Converts MobX 5 to MobX 6 code. Running this code mod: Go to the folder with your source files and run...
Read more >
Common Pitfalls & Best Practices · Mobx Doc - iiunknown
Importing from wrong location · Issues with decorators? · Array.isArray(observable([1,2,3])) === false · object.someNewProp = value is not picked up.
Read more >
MobX (with Decorators) in create-react-app - Robin Wieruch
Running this code in a plain create-react-app application will yield a Unexpected token error in the developer console. You would have to add ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found