salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.64k stars 393 forks source link

Lightning Component cannot access variables exported in LWC module #1850

Open pkozuchowski opened 4 years ago

pkozuchowski commented 4 years ago

Description

When LWC module exports an object (or other non function type variable) and this module is imported in Lightning Component, then exported properties are turned into something looking like a function. The value of exported variables cannot be referenced.

Steps to Reproduce

  1. Create LWC module with shared variables:
    
    const Constants = {
    ACCOUNT_TYPE_WEB: 'Web'
    }

export {Constants}


2. Import module in Lightning Component
```html
<c:constants aura:id="consts"/>

Controller.js

console.log(component.find("consts").Constants);

Expected Results

Lightning Component should be able to reference exported values.

Actual Results

Lightning Component gets strange function-like item that is not usable:

temp1; // component.find("consts").Constants
ƒ (){const o=$r(e,arguments,r);let i=t[n](...o);return r.afterCallback&&(i=r.afterCallback(i)),r.metrics&&Qt(n),Fr(e,i,r)}

temp1();
aura_prod.js:29 Uncaught TypeError: t[n] is not a function
    at Object.value [as Constants] (aura_prod.js:29)
    at <anonymous>:1:7

Browsers Affected

All

Version

Not sure, happens on sandbox.

Possible Solution

Additional context/Screenshots The only workaround I've found for this, is to export function which will return the object.

const Constants = {
    ACCOUNT_TYPE_WEB: 'Web'
}

export function getConstants() {
    return Constants
}
diervo commented 4 years ago

I'm going to close this issue since this has nothing to do with LWC but with the interoperability layer on the Salesforce platform with Aura to which there are other more appropriate channels for.

But before I do that, @jodarove can you take a look? Because any export should just work, sounds like either a corner case or something we team should be trivially able to fix. Modify this issue accordingly.

caridy commented 4 years ago

There is also the locker layer in here, which might be wrapping the imported namespace. cc @dgitin