-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
Affects Version/s: 2.2.0
-
Component/s: None
-
None
-
Environment:OS: Rocky Linux release 8.6 (Green Obsidian)
node.js / npm versions: v18.14.2
MongoDB: mongodb-org 7.0.6
MongoDB Mongosh: 2.2.0
-
Developer Tools
-
Not Needed
Problem Statement/Rationale
When running the Javascript "require" method with the --eval flag, it fails with a reference error.
$ mongosh --eval 'require'
ReferenceError: require is not defined
But when using the interactive mode, everything works as expected.
$ mongosh Current Mongosh Log ID: 65f6e158a958598112db83af Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.0 Using MongoDB: 7.0.6 Using Mongosh: 2.2.0 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ test> require [Function: require] { resolve: [Function: resolve] { paths: [Function: paths] }, main: undefined, extensions: [Object: null prototype] { '.js': [Function (anonymous)], '.json': [Function (anonymous)], '.node': [Function (anonymous)] }, cache: [Object: null prototype] {} }
This behavior changed 3 days ago, when the version 2.2.0 was uploaded to the MongoDB repository (https://github.com/mongodb-js/mongosh/releases)
Current workaround I am using is to force install the 2.1.5 version.
Also, this issue reproduced on Ubuntu 20.04 & 22.04
Steps to Reproduce
Run the following:
mongosh --eval 'require'
Expected Results
$ mongosh --eval 'require' Current Mongosh Log ID: 65f6e158a958598112db83af Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.0 Using MongoDB: 7.0.6 Using Mongosh: 2.2.0 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ [Function: require] { resolve: [Function: resolve] { paths: [Function: paths] }, main: undefined, extensions: [Object: null prototype] { '.js': [Function (anonymous)], '.json': [Function (anonymous)], '.node': [Function (anonymous)] }, cache: [Object: null prototype] {} }
Actual Results
$ mongosh --eval 'require'
ReferenceError: require is not defined
- duplicates
-
MONGOSH-1738 Require not working in script mode
- Closed