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: Cannot read property 'stringify' of undefined (8.3.0 -> 8.4.16) #1767

Closed
Lonli-Lokli opened this issue Aug 11, 2022 · 11 comments
Closed

Comments

@Lonli-Lokli
Copy link

I faced an issue with upgrading my Nx codebase (React+StyledComponents) to the latrst version. The change I noticed is that version goes up 8.3.0 -> 8.4.16
I do not have working small reproduction, if you think you will need it can you explain what sample will satisfy your needs (complexity)

My assumption here is that now this module cannot handle empty files or files without styled components

 $) stylelint "**/*.{ts,tsx}"

TypeError: Cannot read property 'stringify' of undefined
    at Function.stringify (D:\sources\rmboa\node_modules\postcss-syntax\stringify.js:8:38)
    at MapGenerator.generate (D:\sources\rmboa\node_modules\stylelint\node_modules\postcss\lib\map-generator.js:323:12)
    at LazyResult.stringify (D:\sources\rmboa\node_modules\stylelint\node_modules\postcss\lib\lazy-result.js:277:20)
    at LazyResult.runAsync (D:\sources\rmboa\node_modules\stylelint\node_modules\postcss\lib\lazy-result.js:443:17)
    at LazyResult.async (D:\sources\rmboa\node_modules\stylelint\node_modules\postcss\lib\lazy-result.js:221:30)
    at LazyResult.then (D:\sources\rmboa\node_modules\stylelint\node_modules\postcss\lib\lazy-result.js:206:17)
@ai
Copy link
Member

ai commented Aug 11, 2022

Sorry, you need to open this issue in Stylelint.

If you will know what to change in PostCSS core open a new issue.

@ai ai closed this as completed Aug 11, 2022
@AndreyYevtukhov
Copy link

@Lonli-Lokli

did you open that issue in https://github.com/stylelint/stylelint?
or maybe found a solution? :)

@Lonli-Lokli
Copy link
Author

Unfortunately not for both cases. I think it's related to latest changes in postcss to lazy load, but everyone needs a clean simple reproduction without external libraries

@omjokine
Copy link

omjokine commented Aug 15, 2022

I have this same issue. Unfortunately I don't have very simple piece of code to reproduce this issue, but got the same stack trace as OP had.

This happened when updated postcss from 8.4.14 to 8.4.16. So I can reproduce it simply running npm update postcss and then running stylelint. So I guess it is regression in postcss, not in stylelint.

@tomof
Copy link

tomof commented Aug 16, 2022

I faced the same problem. Fortunately, the repository is publicly available, so I will post the URL of the pull request by the Renovate bot that caused the problem. I hope this helps.

@Lonli-Lokli
Copy link
Author

@ai Can you please reiterate this issue? Do you still think it should be fixed in stylelint?

@AndreyYevtukhov
Copy link

we have solved it by adding

"overrides": {
    "postcss": "^8.4.16"
  }

in package.json

@Lonli-Lokli
Copy link
Author

Unfortunately that's only workaround and also requires Node16

@ai
Copy link
Member

ai commented Aug 16, 2022

Can you please reiterate this issue?

I will re-open this issue only if we will have explicit understandard what do we need to change in the core.

Before it, better to discuss it in Stylelint issue.

@Lonli-Lokli
Copy link
Author

Lonli-Lokli commented Aug 16, 2022

@ai Here is my findings.
postcss-syntax expecting to have document (aka root) to be Document
https://github.com/gucong3000/postcss-syntax/blob/master/stringify.js#L5-L7

Which does not happen with new version

postcss/lib/container.js

Lines 419 to 429 in bc5b964

if (node.type === 'atrule') {
Object.setPrototypeOf(node, AtRule.prototype)
} else if (node.type === 'rule') {
Object.setPrototypeOf(node, Rule.prototype)
} else if (node.type === 'decl') {
Object.setPrototypeOf(node, Declaration.prototype)
} else if (node.type === 'comment') {
Object.setPrototypeOf(node, Comment.prototype)
} else if (node.type === 'root') {
Object.setPrototypeOf(node, Root.prototype)
}

While was happening with the old one

postcss/lib/container.js

Lines 415 to 423 in b7d1836

if (node.type === 'atrule') {
Object.setPrototypeOf(node, AtRule.prototype)
} else if (node.type === 'rule') {
Object.setPrototypeOf(node, Rule.prototype)
} else if (node.type === 'decl') {
Object.setPrototypeOf(node, Declaration.prototype)
} else if (node.type === 'comment') {
Object.setPrototypeOf(node, Comment.prototype)
}

As a result stringifier goes into the https://github.com/gucong3000/postcss-syntax/blob/master/stringify.js#L8
source property does not exists and we are facing an issue.

@ai
Copy link
Member

ai commented Aug 17, 2022

Seems like postcss-syntax is hack the AST.

We can’t just remove node.type === 'root' because it is fixed another bug.

Here are my suggestions:

  1. Fix Stylelint and set .source.syntax.stringify to some custom analog of docStringify
  2. Find a way to detect Document from postcss-syntax and avoid conversation. But I afraid it will break AST normalization fix.

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

5 participants