Skip to main content
1-Visitor
September 30, 2017
Question

require is not defined

  • September 30, 2017
  • 2 replies
  • 3149 views

Hello There,

     i'm trying to write a javascript code inside thingworx from Services tab.

but when i tested the script it gave me this error 'require is not defined'

is there any solution for this issue.

Br,

Mohamed Ewees.

    2 replies

    16-Pearl
    October 1, 2017

    Can you paste the javascript - difficult to under the error message without

    5-Regular Member
    October 2, 2017

    I think somehow you are using require() function in your code ,that's why you are getting some reference error .By default require() is not a valid function in client side JS. you need to extend the JS to have the function require() by looking into require.js .

    I think i am taking this into right direction ,as you only mentioned the error ,full JS code will be more helpful to check this out .

    Thanks

    Mukul Narang

    mewees1-VisitorAuthor
    1-Visitor
    October 2, 2017

    Hi Mukul,

         thanks a lot for your response.

    i'm trying to do something like "var http = require("https"); " but  it gave me this error 'require is not defined'.

    so , how can i extend the JS to have the function require() by looking into require.js

    5-Regular Member
    October 7, 2017

    Thingworx Services are not able to import libraries like in node.js. If you are trying to call a REST or SOAP service, check out the snippets for ContentLoaderFunctions, this will let you do things like GET/POST/PUT requests.