Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Undefined error while loading SurveyJS using RequireJS

I am trying to run the simple survey using SurveyJS and it is not getting loaded by requireJS. There is no error on loading, but it is undefined inside the define function's body.

I have tried to use shim's exports property, however the result was the same.

What possibly am I doing wrong?

index.js

requirejs.config({
  paths: {
    app: "./",
    jquery: 'https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min',
    Survey: "https://unpkg.com/survey-jquery@1.9.40/survey.jquery.min",
  },
  shim: {
    Survey: {
      deps: ['jquery'],
    }
  }
});

requirejs(["main"]);

main.js

define(["Survey"], function (Survey) {
  console.log(Survey); // undefined
});

index.html


<head>
    <script data-main="index" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
    <link href="index.css" rel="stylesheet" />

<link href="https://unpkg.com/survey-jquery@1.9.40/modern.css" type="text/css" rel="stylesheet"/>
</head>
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Turns out, that each module can have their own name inside the library. For SurveyJS it is survey-jquery. And it does not require the usage of shim part of requirejs.

Had to look at the library's beginning part where it defines it. Also, it requires jQuery to be defined as jquery.

function webpackUniversalModuleDefinition(root, factory) {
    if(typeof exports === 'object' && typeof module === 'object')
        module.exports = factory(require("jquery"));
    else if(typeof define === 'function' && define.amd)
        define("survey-jquery", ["jquery"], factory);
    else if(typeof exports === 'object')
        exports["survey-jquery"] = factory(require("jquery"));
    else
        root["Survey"] = factory(root["jQuery"]);
}

Changed index.js as below

require.config({
  paths: {
    app: "./",
    jquery: 'https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min',
    'survey-jquery': "https://unpkg.com/survey-jquery@1.9.40/survey.jquery.min",
  },
});

As the imported module name has changed, so changed main.js

define(["survey-jquery"], function (Survey) {
  console.log(Survey); // Module {...}
});
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!