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

Error: LWC1702: lwc => import {createElement} from 'lwc'; seems to be broken? #350

Closed
erocheleau opened this issue Feb 19, 2024 · 6 comments

Comments

@erocheleau
Copy link

erocheleau commented Feb 19, 2024

Description

VSCode is just showing a cryptic error
image
on the line import {createElement} from 'lwc'; where it wasn't before?

It looks like I can change it to import {createElement} from '@lwc/engine-dom'; but I'm afraid it might cause other issues?

Steps to Reproduce

Even in the lwc-recipe repository I am having this error.

import {createElement} from 'lwc';

Expected Results

No errors I guess?

Actual Results

image

Version

  • @salesforce/sfdx-lwc-jest: 3.1.2
  • Node: v18.19.0

The import in the jest files seems to resolve to this .d.ts from the .sfdx folder that gets created every time I run a sf command from inside the project for instance.

image

@nolanlawson
Copy link
Contributor

Thanks for reporting!

import {createElement} from 'lwc' is disallowed on platform due to this ESLint rule. That said, people use it in their Jest tests all the time, and we don't have a problem with that.

Questions:

  1. Are you using this in a Jest test or a component file?
  2. Is this a new issue that popped up recently? What caused it?
  3. What is this preventing you from doing? (E.g. publishing, running tests, etc.)

@erocheleau
Copy link
Author

Thanks for reporting!

import {createElement} from 'lwc' is disallowed on platform due to this ESLint rule. That said, people use it in their Jest tests all the time, and we don't have a problem with that.

Questions:

  1. Are you using this in a Jest test or a component file?

Yes that's what I meant, sorry if that wasn't clear. It's in all the Jest test files, following the example of tests given by Salesforce or other GitHub repos.

  1. Is this a new issue that popped up recently? What caused it?

I don't have a specific cause for the issue unfortunately, I am part of multiple repositories, all running different versions of sfdx-lwc-jest. Could've been perhaps related to an update of the ESLint plugin?

  1. What is this preventing you from doing? (E.g. publishing, running tests, etc.)

Enjoying my "error-less" files :) It's not blocking anything, but it's just annoying.

// @ts-ignore
doesn't even resolve it, but VSCode resolves the imports from 'lwc' to a typings file in .sfdx/typings IIRC, which doesn't have an exported createElement on it.
Wondering if perhaps there should just be a typings file specific to the 'lwc' imported while writing lwc-Jest tests?

@BatemanVO
Copy link

Adding that I also see this highlight in VSCode with sfdx-lwc-jest 4.0.1, even though running npx eslint on the directory won't actually throw any errors. If I had not seen this issue, I don't think I would've even noticed anything wrong.

I did try updating our .eslintrc.json file to include:

"@lwc/lwc/valid-api": ["error", { "allowList": ["createElement"] }]

but that didn't resolve the issue.

@nolanlawson
Copy link
Contributor

Thanks for the confirmation. So it sounds like this might actually be an issue purely in the VS Code Extension? It sounds like you are just seeing a red squiggly in the VS Code UI, but you can't actually reproduce the ESLint error by running eslint on the command line.

If that's the case, then this may have been due to a change in lightning-language-server (which the VS Code extension uses).

@erocheleau
Copy link
Author

@nolanlawson perhaps, do you have any idea to try to hide this?

@nolanlawson
Copy link
Contributor

Based on the description above, I am closing this issue in favor of an issue on forcedotcom/lightning-language-server. Could you please provide your VS Code version, SFDX CLI version, and OS version in that thread? Thank you!

New issue: forcedotcom/lightning-language-server#588

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

3 participants