prettier-plugin-sort-imports
prettier-plugin-sort-imports copied to clipboard
SyntaxError: Unexpected token. Nestjs + prettier-plugin-sort-imports
Your Environment
- Prettier version: 2.6.2
- node version: 16.16.0
- package manager: [email protected]
- prettier-plugin-sort-import: 3.3.0
- Nestjs: 9.0.7
- IDE: VScode
Describe the bug
First error
When I add this prettier-plugin-sort-import with no configuration I have an error like this:
SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "decorators-legacy", "decorators"
Second error
When I add decorators configuration:
"importOrderParserPlugins": ["classProperties", "decorators-legacy"]
have this error on each ts file:
SyntaxError: Missing semicolon.
SyntaxError: Unexpected reserved word 'private'
SyntaxError: Unexpected token, expected "{"
To Reproduce
Running prettier command to fix issues:
prettier --write **/*.{ts,js,json,md,html}
Expected behavior
No Syntax error using prettier-plugin-sort-imports
Screenshots, code sample, etc
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
First error
.prettierrc
{
"semi": false,
"trailingComma": "none",
"tabWidth": 2,
"arrowParens": "always",
"printWidth": 100,
"singleQuote": false,
"bracketSpacing": true,
"endOfLine": "auto",
"importOrder": ["^@nestjs/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
Second error:
.prettierrc
{
"semi": false,
"trailingComma": "none",
"tabWidth": 2,
"arrowParens": "always",
"printWidth": 100,
"singleQuote": false,
"bracketSpacing": true,
"endOfLine": "auto",
"importOrder": ["^@nestjs/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"importOrderParserPlugins": ["classProperties", "decorators-legacy"]
}
I've solved this problem by adding a more value typescript
on importOrderParserPlugins
.
@samchon And what exactly values did you add there that everything worked?
@ducker-dev "importOrderParserPlugins": ["typescript", "classProperties", "decorators-legacy"]
I have this config
importOrderParserPlugins: [
'typescript',
'classProperties',
"[\"decorators\", { \"decoratorsBeforeExport\": true }]"
],
but now I'm getting this SyntaxError: Decorators cannot be used to decorate parameters.
I'm using NestJS