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

TypeError: this.getPosition is not a function in LessParser.inlineComment #5666

Closed
PlayApple opened this issue Oct 28, 2021 · 17 comments
Closed
Labels
status: needs clarification triage needs clarification from author

Comments

@PlayApple
Copy link

TypeError: this.getPosition is not a function

"lint:style": "stylelint --fix "src/**/*.less" --custom-syntax postcss-less"

TypeError: this.getPosition is not a function
at LessParser.inlineComment (/web/node_modules/postcss-less/lib/LessParser.js:71:28)
at LessParser.isInlineComment (/web/node_modules/postcss-less/lib/nodes/inline-comment.js:37:12)
at LessParser.other (/web/node_modules/postcss-less/lib/LessParser.js:156:36)
at LessParser.parse (/web/node_modules/postcss/lib/parser.js:75:16)
at parse (/web/node_modules/postcss-less/lib/index.js:11:12)
at new LazyResult (/web/node_modules/stylelint/node_modules/postcss/lib/lazy-result.js:133:16)
at getPostcssResult (/web/node_modules/stylelint/lib/getPostcssResult.js:77:30)
at async lintSource (/web/node_modules/stylelint/lib/lintSource.js:76:4)
at async /web/node_modules/stylelint/lib/standalone.js:218:27
at async Promise.all (index 0)

How can i fixed it. Thanks.

@ybiquitous
Copy link
Member

@PlayApple Can you reproduce the error on the demo?

Also, please use the issue template for a bug report.

@strigefleur
Copy link
Contributor

@PlayApple you probably forgot to install postcss itself.
I believe postcss-less not gonna work without it.

@PlayApple
Copy link
Author

Sorry , i upload the demo project.

myapp.zip

`yarn lint
yarn run v1.22.15
$ umi g tmp && npm run lint:js && npm run lint:style && npm run lint:prettier && npm run tsc
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating

ant-design-pro@5.0.0 lint:js /demo/myapp
eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src

ant-design-pro@5.0.0 lint:style /demo/myapp
stylelint --fix "src/**/*.less" --custom-syntax postcss-less

TypeError: this.getPosition is not a function
at LessParser.inlineComment (/demo/myapp/node_modules/postcss-less/lib/LessParser.js:71:28)
at LessParser.isInlineComment (/demo/myapp/node_modules/postcss-less/lib/nodes/inline-comment.js:37:12)
at LessParser.other (/demo/myapp/node_modules/postcss-less/lib/LessParser.js:156:36)
at LessParser.parse (/demo/myapp/node_modules/postcss/lib/parser.js:75:16)
at parse (/demo/myapp/node_modules/postcss-less/lib/index.js:11:12)
at new LazyResult (/demo/myapp/node_modules/stylelint/node_modules/postcss/lib/lazy-result.js:133:16)
at getPostcssResult (/demo/myapp/node_modules/stylelint/lib/getPostcssResult.js:77:30)
at async lintSource (/demo/myapp/node_modules/stylelint/lib/lintSource.js:76:4)
at async /demo/myapp/node_modules/stylelint/lib/standalone.js:218:27
at async Promise.all (index 0)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ant-design-pro@5.0.0 lint:style: stylelint --fix "src/**/*.less" --custom-syntax postcss-less
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ant-design-pro@5.0.0 lint:style script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/liuyanghui/.npm/_logs/2021-10-28T13_45_03_497Z-debug.log
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.`

@alexander-akait
Copy link
Member

Run npm ls postcss-less

@PlayApple
Copy link
Author

yarn install
yarn lint Will go wrong

@alexander-akait
Copy link
Member

Please run command above

@PlayApple
Copy link
Author

image

@ybiquitous ybiquitous added the status: needs clarification triage needs clarification from author label Oct 28, 2021
@lachieh
Copy link
Contributor

lachieh commented Oct 28, 2021

Can you do the same with npm ls postcss?

It seems like postcss-less depends on postcss@8, but doesn't has it listed in devDependencies which might be preventing it from adding the dependency? Anyone have any more insight into how npm/yarn handles deduping devDependencies? I think maybe postcss-less needs to add postcss@8 as a peer dependency?

Running yarn add postcss@8 fixes the issue, but it probably shouldn't be the permanent fix.

@ybiquitous
Copy link
Member

@PlayApple Your project's postcss version seems outdated.

$ node -pe 'require("postcss/package.json").version'
7.0.39

postcss-less@5.0.0 requires postcss@8. See below:
https://github.com/shellscape/postcss-less/blob/v5.0.0/package.json#L44

@jeddy3 jeddy3 closed this as completed Oct 28, 2021
@PlayApple
Copy link
Author

npm ls postcss

image

@lachieh
Copy link
Contributor

lachieh commented Oct 29, 2021

@PlayApple run this:
yarn add postcss@8

@zheeeng
Copy link

zheeeng commented Nov 4, 2021

@lachieh @alexander-akait I'm using PNPM and encountered the same problem.

pnpm ls postcss-less

devDependencies:
postcss-less 5.0.0
pnpm ls postcss

devDependencies:
postcss 8.3.11

@NansD
Copy link

NansD commented Dec 1, 2021

I have the same issue with

└─ postcss-less@5.0.0

and

│  └─ postcss@8.4.4
├─ postcss-safe-parser@5.0.2
│  └─ postcss@8.4.4
├─ postcss@7.0.39
├─ resolve-url-loader@3.1.4
│  └─ postcss@7.0.36
└─ stylelint@14.1.0
   └─ postcss@8.4.4

is there something I'm doing wrong ?

@ybiquitous
Copy link
Member

ybiquitous commented Dec 1, 2021

@NansD Can you provide your .stylelintrc file, please? I'm curious where customSyntax: 'postcss-less' is.

EDIT: Please see also #5632 (comment)

@NansD
Copy link

NansD commented Dec 2, 2021

Thank you for your help !

my .stylelintrc.json was like this :

{
  "extends": "stylelint-config-standard",
  "customSyntax": "postcss-less"
}

And I just tried transforming it to a js file like so :

module.exports = {
  "extends": "stylelint-config-standard",
  "customSyntax": require("postcss-less")
}

but still get TypeError: this.getPosition is not a function

@cong1223
Copy link

if you use less , these deps you have to install :
"postcss": "8", "postcss-less": "^6.0.0", "stylelint": "^14.5.1", "stylelint-config-recommended-less": "^1.0.4",

@NansD
Copy link

NansD commented Mar 24, 2022

It works, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs clarification triage needs clarification from author
Development

No branches or pull requests

9 participants