3

Seems there is something in the script that is preventing it from loading.....

From Lightning Compopnent

Uncaught Action failed: CP2$C_Payment_Entry$controller$validateCardNumber [payform is not defined]
throws at https://Cp2-dev-ed.lightning.force.com/auraFW/javascript/C9w03EpEHI__XcCDlMV8MQ/aura_prod.js:2:15
    at validateCardNumber (components/CP2/C_Payment_Entry.js:46:24)
    at G.Bc (https://Cp2-dev-ed.lightning.force.com/auraFW/javascript/C9w03EpEHI__XcCDlMV8MQ/aura_prod.js:305:170)
    at Object.c [as Sa] (https://Cp2-dev-ed.lightning.force.com/auraFW/javascript/C9w03EpEHI__XcCDlMV8MQ/aura_prod.js:256:213)
    at JA (https://Cp2-dev-ed.lightning.force.com/auraFW/javascript/C9w03EpEHI__XcCDlMV8MQ/aura_prod.js:294:461)
    at https://Cp2-dev-ed.lightning.force.com/auraFW/javascript/C9w03EpEHI__XcCDlMV8MQ/aura_prod.js:295:281
    at Z.A.mb (https://Cp2-dev-ed.lightning.force.com/auraFW/javascript/C9w03EpEHI__XcCDlMV8MQ/aura_prod.js:626:227)
    at O.N (https://Cp2-dev-ed.lightning.force.com/auraFW/javascript/C9w03EpEHI__XcCDlMV8MQ/aura_prod.js:295:260)
    at Object.fireEvent (libraries/one/s1MetricsServicePlugins/navigationContext.js:5590:280)
    at Object.fireEvent (libraries/one/s1MetricsServicePlugins/navigationContext.js:163:52)
    at HTMLInputElement.domEventHandler (libraries/one/s1MetricsServicePlugins/navigationContext.js:5590:21)

When using a VF Page and Lightning Out

I simply get this message

Uncaught TypeError: Cannot set property 'payform' of undefined throws at /resource/1484234883000/CP2__Assets/js/payform.js:22:25

THIS is the line that is causing the issue:

})('payform', function() {

Maybe that will be helpful

Have anyone encountered this issue before? Heck I do not even know what the issue is.

In case it matters this is also displayed in lightning:

This page has an error. You might just need to refresh it. First, would you give us some details? (We're reporting this as error ID: 64be56e1-0811-4cce-8418-12be0fdf71b4)

Library I am loading is located here:

https://github.com/jondavidjohn/payform/blob/master/dist/payform.js

The inability to use a JS library will halt our development of Lightning components since the Locker Service will be a mandatory thing it would be helpful to know what needs to be done to get this working.

Any inputs would be helpful.

2
  • Is there any component by name 'C_Payment_Entry.' ? Can you post the code post that or just the line 46 (+- 4) lines of that component.
    – manjit5190
    Jan 12, 2017 at 18:31
  • @manjit_singh - That line is basically attempting to access the JS library 'payment' object. The main issue seems to be the IIFE and the way the library is doing things. It works fine without locker so....
    – Eric
    Jan 12, 2017 at 18:41

2 Answers 2

2

@Eric manjit_singh is correct. The third party libraries need to be strict mode compliant to be able to work under locker service. So in your library code, if you change L20 return this[name] = definition(); to return window[name] = definition(); it should start working as expected.

https://github.com/jondavidjohn/payform/blob/master/dist/payform.js#L20

2
  • I will give this a try, thank you.....Question, if window[name] works in strict and non strict mode why would one use this? A bit off topic here but not being a java developer that was the first question that came to mind.
    – Eric
    Jan 13, 2017 at 19:00
  • Again, thank you. I do not think I would have ever got to that point (editing that line) as I would have broke the code long before trying that lol.....Now I have the understanding of why, how, and what to look out for. Appreciate you taking the time to review the issue and provide the answer.
    – Eric
    Jan 13, 2017 at 19:13
3

The JS code that runs in the locker service runs in strict mode I think.

The error is in this line return this[name] = definition(); where this is passed as undefined in strict mode and does not refers to global window object.

I belive you can tweak the library to pass in certain parameter/argument or use the internal IIFE to create your own implementation.

2
  • Thank you for the answer. I am no JS expert so I guess I will just have to find another way cause I do not have time to learn how to adjust it without breaking it lol....But I may give the good ol college try in a bit. Also, I am 99% sure you are correct but will give it a few before accepting..
    – Eric
    Jan 12, 2017 at 20:18
  • 1
    Your answer was very useful and Ravi's answer completes it. Appreciate it.
    – Eric
    Jan 13, 2017 at 19:19

You must log in to answer this question.

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