3

I am trying to figure out if we can truly enable dynamicImports? I see that that the LWC Compiler has a babel config flag that can enable it, and there are even tests that use this setting but I do not know how to turn it on.

When trying to run this line:

const template = import(`./templates/${this.type}View.html`);

I get the following error:

LWC1509: This experimental syntax requires enabling the parser plugin: 'dynamicImport'.

Is this possible for me to enable since it is telling me to, and if so how do I enable 'dynamicImport'

References: https://github.com/salesforce/lwc/blob/55b962b61a8d38495a9d4584d5315a0fd2ab1d50/packages/%40lwc/babel-plugin-component/src/index.js

https://github.com/salesforce/lwc/blob/55b962b61a8d38495a9d4584d5315a0fd2ab1d50/packages/%40lwc/compiler/src/babel-plugins.ts

1 Answer 1

5
  1. No - dynamic Imports are not available on platform. You have linked the oss LWC Compiler which does not have to match the version / restrictions of the one used for the SFDC Platform
  2. There was just 2 days ago a PR raised for adding supporting - but before the release of the next Major Version AFTER the Merge you should not expect it to be available (and even that is not guaranteed - as long as you don`t see it in the release notes it wont be available)
  3. Your Example would not work anyways - the build tool needs to know at compile which package have to be imported. You can`t use variable interpolation - it needs to be a static string
1
  • 2
    thank you for a response. Ok so short story is no. Interesting because const template = require(./templates/${this.type}View.html); worked for over a month and all of a sudden that doesn't work either. Just trying to find another way to dynamically load template files, not whole components.
    – Brandon
    Commented Jul 10, 2019 at 21:48

You must log in to answer this question.

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