首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义BSONRmgExp

未定义BSONRmgExp
EN

Stack Overflow用户
提问于 2020-07-30 17:25:48
回答 1查看 79关注 0票数 0

我正在学习一个Node.js教程,我们刚刚开始使用Mongoose。直到今天,一切都很顺利。我打开电脑,打开WebStorm。我去运行我们上一次的工作,我得到了下面的堆栈跟踪:

代码语言:javascript
复制
/usr/bin/node /home/doug/Documents/node-course/task-manager/src/db/mongoose.js
/home/doug/Documents/node-course/task-manager/node_modules/bson/index.js:41
BSON.BSONRegExp = BSONRmgExp;
                  ^

ReferenceError: BSONRmgExp is not defined
    at Object.<anonymous> (/home/doug/Documents/node-course/task-manager/node_modules/bson/index.js:41:19)
    at Module._compile (internal/modules/cjs/loader.js:1236:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)
    at Module.load (internal/modules/cjs/loader.js:1085:32)
    at Function.Module._load (internal/modules/cjs/loader.js:950:14)
    at Module.require (internal/modules/cjs/loader.js:1125:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at Object.<anonymous> (/home/doug/Documents/node-course/task-manager/node_modules/mongodb/lib/core/index.js:3:12)
    at Module._compile (internal/modules/cjs/loader.js:1236:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)

Process finished with exit code 1

下面是我的代码:

代码语言:javascript
复制
const mongoose = require('mongoose');
//
// // mongoose.connect('mongodb://127.0.0.1:27017/task-manager-api', {
// //     useNewUrlParser: true,
// //     useCreateIndex: true
// // });
//
// // const User = mongoose.model('User', {
// //     name: {
// //         type: String,
// //     },
// //     age: {
// //         type: Number
// //     }
// // });
//
//
// // const Task = mongoose.model('Task', {
// //     description: {
// //         type: String
// //     },
// //     completed: {
// //         type: Boolean
// //     }
// // });
//
// //
// // const newTask = new Task({
// //     description: 'This is a new task added by mongoose.',
// //     completed: false
// // });
// //
// // newTask.save().then((newTask) => {
// //     console.log(newTask);
// // }).catch((error) => {
// //     console.log('Error!', error);
// // });
//
// // const me = new User({
// //     name: 'Doug',
// //     age: 30
// // });
// //
// // me.save().then((me) => {
// //     console.log(me);
// // }).catch((error) => {
// //     console.log('Error!', error);
// // });

除了我的需要之外,所有的东西都被注释掉了,我仍然得到了错误。如果我注释掉了require,它就会运行。

搜索"ReferenceError: BSONRmgExp is not defined“,我什么也找不到。

有没有人有关于如何解决这个问题的建议,或者是什么导致了这个问题?

编辑:这是它引用的文件,它位于node_modules文件夹中。

index.js

代码语言:javascript
复制
var BSON = require('./lib/bson/bson'),
  Binary = require('./lib/bson/binary'),
  Code = require('./lib/bson/code'),
  DBRef = require('./lib/bson/db_ref'),
  Decimal128 = require('./lib/bson/decimal128'),
  Double = require('./lib/bson/double'),
  Int32 = require('./lib/bson/int_32'),
  Long = require('./lib/bson/long'),
  Map = require('./lib/bson/map'),
  MaxKey = require('./lib/bson/max_key'),
  MinKey = require('./lib/bson/min_key'),
  ObjectId = require('./lib/bson/objectid'),
  BSONRegExp = require('./lib/bson/regexp'),
  Symbol = require('./lib/bson/symbol'),
  Timestamp = require('./lib/bson/timestamp');

// BSON MAX VALUES
BSON.BSON_INT32_MAX = 0x7fffffff;
BSON.BSON_INT32_MIN = -0x80000000;

BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1;
BSON.BSON_INT64_MIN = -Math.pow(2, 63);

// JS MAX PRECISE VALUES
BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double.
BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double.

// Add BSON types to function creation
BSON.Binary = Binary;
BSON.Code = Code;
BSON.DBRef = DBRef;
BSON.Decimal128 = Decimal128;
BSON.Double = Double;
BSON.Int32 = Int32;
BSON.Long = Long;
BSON.Map = Map;
BSON.MaxKey = MaxKey;
BSON.MinKey = MinKey;
BSON.ObjectId = ObjectId;
BSON.ObjectID = ObjectId;
// BSON.BSONRegExp = BSONRmgExp;
BSON.Symbol = Symbol;
BSON.Timestamp = Timestamp;

// Return the BSON
module.exports = BSON;

如果我注释掉行"BSON.BSONRegExp = BSONRmgExp;",那么一切都会运行。我试着在谷歌上搜索引文中的这一行,但没有结果。

编辑2:我猜这与MongoDB有关,但这个特定问题的documentation isn't very helpful

EN

回答 1

Stack Overflow用户

发布于 2020-09-15 16:44:23

尝试了BSON.BSONRegExp = BSONRegExp;而不是BSON.BSONRegExp = BSONRmgExp;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63170126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档