1

I have this custom lightning web component

import {LightningElement, api, createElement } from 'lwc';

export default class Tm_customLWCGenerator extends LightningElement {

}

And when I try to save and deploy to org it gives me the following error:

Error 57 [Line: 1, Col: 13] LWC1518: Invalid LWC imported identifier "createElement"

This is my meta.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>46</apiVersion>
<description>Generates custom lightning web component based on componentName, componentClass and api variables</description>
<masterLabel>masterLabelForLWC</masterLabel>
</LightningComponentBundle>

Is there something that I'm doing wrong? Cause I see many references using this createElement but it's not working for me.

2 Answers 2

5

TL;DR: you can't use createElement on the Salesforce Platform.

Dynamic component creation isn't available in Lightning Web Component on the Salesforce Platform, mostly for performance reasons.
You can get more details from a team architect here.

There is a RFC for it here, and discussions about potential implementation has started here.

1
  • Thanks! I'll go for a custom approach then.
    – molinet
    Sep 25, 2019 at 9:49
0

Try:

import { LightningElement, api } from 'lwc';

import { createElement } from 'lwc';

export default class Tm_customLWCGenerator extends LightningElement {

}

This looks weird but it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .