open-wc / custom-elements-manifest

Custom Elements Manifest is a file format that describes custom elements in your project.
https://custom-elements-manifest.open-wc.org/
234 stars 43 forks source link

Error: [CORE - LIT-STATIC-PROPERTIES]: Looks like you've hit an error in the core library. #163

Closed domoskanonos closed 1 year ago

domoskanonos commented 2 years ago

NPM command: custom-elements-manifest analyze --outdir public/ --litelement --dev

with node version 14.17.0 everything works fine, version 16.14.2 broken with error:

TypeError: Cannot read properties of undefined (reading 'push') at mapClassMember (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js:242:27) at file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js:211:35 at Array.forEach () at visitNode (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js:211:12) at visitNodes (C:\machineroom\git\ui-blueprint-webcomponent\blueprint-frontend\node_modules\@custom-elements-manifest\analyzer\node_modules\typescript\lib\typescript.js:29004:30) at Object.forEachChild (C:\machineroom\git\ui-blueprint-webcomponent\blueprint-frontend\node_modules\@custom-elements-manifest\analyzer\node_modules\typescript\lib\typescript.js:29316:21) at visitNode (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js:216:8) at getDefaultValuesFromConstructorVisitor (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js:200:3) at analyzePhase (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/static-properties.js:75:11) at file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/create.js:104:23

at withErrorHandling (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/utils/index.js:67:11)
at file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/create.js:103:7
at Array.forEach (<anonymous>)
at visitNode (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/create.js:102:19)
at visitNodes (C:\machineroom\git\ui-blueprint-webcomponent\blueprint-frontend\node_modules\@custom-elements-manifest\analyzer\node_modules\typescript\lib\typescript.js:29004:30)
at Object.forEachChild (C:\machineroom\git\ui-blueprint-webcomponent\blueprint-frontend\node_modules\@custom-elements-manifest\analyzer\node_modules\typescript\lib\typescript.js:29241:24)
at visitNode (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/create.js:108:8)
at visitNode (C:\machineroom\git\ui-blueprint-webcomponent\blueprint-frontend\node_modules\@custom-elements-manifest\analyzer\node_modules\typescript\lib\typescript.js:28995:24)
at Object.forEachChild (C:\machineroom\git\ui-blueprint-webcomponent\blueprint-frontend\node_modules\@custom-elements-manifest\analyzer\node_modules\typescript\lib\typescript.js:29125:21)
at visitNode (file:///C:/machineroom/git/ui-blueprint-webcomponent/blueprint-frontend/node_modules/@custom-elements-manifest/analyzer/src/create.js:108:8)
thepassle commented 2 years ago

could you post some reproduction code please? :)

Seems like currClass https://github.com/open-wc/custom-elements-manifest/blob/e5eca5bbd4407b90c2801e0c9634cba7bcfe7b8e/packages/analyzer/src/features/framework-plugins/lit/static-properties.js#L75

which we get from here https://github.com/open-wc/custom-elements-manifest/blob/e5eca5bbd4407b90c2801e0c9634cba7bcfe7b8e/packages/analyzer/src/features/framework-plugins/lit/static-properties.js#L18

is not found for some reason, gotta figure out why, but need some reproduction code/playground url to be able to investigate

Not sure why different node versions would have anything to do with it though, we don't really do anything exotic in that regard.

domoskanonos commented 2 years ago

import {LitElement, TemplateResult, html} from "lit"; import {customElement, property} from "lit/decorators.js"; import {environment} from "../environments/environment"; import {OpenidService} from "../service/openid-service";

@customElement("si-ui-blueprint-webcomponent") export class SiUiBlueprintWebcomponent extends LitElement {

@property({type: String})
status: string = "success";

public render(): TemplateResult {
    return html`Something to render `;
}

private login(): void {

}

private newListItem(text: string) {
    return html`
       something`;
}

}

domoskanonos commented 2 years ago

lit version is: "lit": "2.2.1",

thepassle commented 2 years ago

Im not able to reproduce locally or in the playground image

Do note that you're importing

import {customElement, property} from "lit/decorators.js";

but using it with a capital:

@CustomElement("si-ui-blueprint-webcomponent")
domoskanonos commented 2 years ago

@CustomElement -> git automatically capitalized it

domoskanonos commented 2 years ago

in my code it's lowercase "c"

domoskanonos commented 2 years ago

ok i will try to find out where the problem is and i will report here. If i remove "--litElement" flag it works...

domoskanonos commented 2 years ago

exact environment : node: v16.14.2, npm: 8.5.0

valentindiehl commented 2 years ago

@domoskanonos Have you found a solution for this? I'm having the same issue, but I'm trying for days to find the source since it randomly appeared without really changing or updating anything.

As soon as I find a minimal example without 300 lines of code, I'll post it here.

valentindiehl commented 2 years ago

To add to this: The error already happens when running "npm install", not even while transpiling with run/build

DeepakJY97SF commented 2 years ago

I fixed this issue in the createClass.js by checking for classTemplate.members existence and initialize it with empty array if undefined

old:

  if (!existingMember) {
    if (hasIgnoreJSDoc(statement)) return;
    if (isBindCall(statement)) return;

    existingMember = {
      kind: 'field',
      name: expression?.left?.name?.getText(),
    }
    classTemplate.members.push(existingMember);
  }

new:

  if (!existingMember) {
    if (hasIgnoreJSDoc(statement)) return;
    if (isBindCall(statement)) return;

    existingMember = {
      kind: 'field',
      name: expression?.left?.name?.getText(),
    }
    if(!classTemplate.members){
      classTemplate.members = [];
    }
    classTemplate.members.push(existingMember);
  }

I tried to push a fix branch to create a pullrequest, but I don't have the rights

KameronKales commented 1 year ago

I had this issue (independent of which node version I was running, i tried 14 and 16).

Version: "@custom-elements-manifest/analyzer": "^0.6.4"

I was able to fix by being verify specific about what code to include via --glob.

For a project im working on

This works:

cem analyze --litelement --globs packages/*/* --exclude packages/*/dist

This does not

cem analyze --litelement --exclude packages/*/dist

and this does not

cem analyze --litelement --globs packages/*/*

Obviously YMMV but changing this command got me up and running again. Im assuming there is some code in my project that is causing the issue and I should have been using globs all along