Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1738

Require not working in script mode

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      OS:
      node.js / npm versions:
      Additional info:
    • Not Needed
    • Developer Tools

      Problem Statement/Rationale

      My customer encountered an issue while testing the new version in their environment. Specifically, they faced problems related to using dependencies with require.
      When they run the following  script with mongosh:
       

      function test() 
      { 
         const mathjs = require('mathjs'); 
         return { 
                 mathjs: mathjs.evaluate('12.7 cm to inch'), 
         } 
      }
       console.log(test());
       

      It resulted in a ReferenceError: require is not defined. Has the dependency management changed from mongosh 1.* to mongosh2.2?

      The script worked correctly with mongosh 1.8.2. Unfortunately, this issue is hindering their benchmarking process.

      Please be sure to attach relevant logs with any sensitive data redacted.
      How to retrieve logs for: Compass; Shell

      Steps to Reproduce

      Run the script above

      Expected Results

      Require to not error

      Actual Results

      Require is erroring

      Additional Notes

      Any additional information that may be useful to include.

            Assignee:
            kevin.mas@mongodb.com Kevin Mas Ruiz
            Reporter:
            gaurab.aryal@mongodb.com Gaurab Aryal
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: