admin管理员组文章数量:1201414
I am running this on Node.js version 6.9.5
I have this code:
let {Schema}, mongoose = require('mongoose');
which is in theory a simplified version of:
let mongoose = require('mongoose');
let Schema = mongoose.Schema;
I get this error:
let {Schema}, mongoose = require('mongoose');
^^^^^^^^
SyntaxError: Missing initializer in destructuring declaration
I tried this instead:
let mongoose, {Schema} = require('mongoose');
I got a different error, which was the result of "mongoose" being undefined.
I thought it was possible to do something like this, what am I doing wrong?
I am running this on Node.js version 6.9.5
I have this code:
let {Schema}, mongoose = require('mongoose');
which is in theory a simplified version of:
let mongoose = require('mongoose');
let Schema = mongoose.Schema;
I get this error:
let {Schema}, mongoose = require('mongoose');
^^^^^^^^
SyntaxError: Missing initializer in destructuring declaration
I tried this instead:
let mongoose, {Schema} = require('mongoose');
I got a different error, which was the result of "mongoose" being undefined.
I thought it was possible to do something like this, what am I doing wrong?
Share Improve this question asked May 1, 2017 at 20:23 Alexander MillsAlexander Mills 100k165 gold badges531 silver badges908 bronze badges 3 |4 Answers
Reset to default 14No.
let {Schema}, mongoose = require('mongoose');
it's same as
let {Schema};
let mongoose = require('mongoose');`
so it will not work because it's not exists object wherefrom take Schema
.
let mongoose, {Schema} = require('mongoose');
it's same as
let mongoose;
let {Schema} = require('mongoose');`
And mongoose
is really undefined.
For me it was because I was returning empty variables so I had to check their values. Make sure you're returning the right data.
In my case, I was missing an extra }
at the end of useEffect
In my case, that was because of the syntax. With node v18.7.0
and with basic JS (not typescript), I should use (with your example):
import mongoose, {Schema} = from 'mongoose';
本文标签: javascriptSyntaxError Missing initializer in destructuring declarationStack Overflow
版权声明:本文标题:javascript - SyntaxError: Missing initializer in destructuring declaration - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738632603a2103836.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
let {Schema}, mongoose = require('mongoose');
it's same aslet {Schema}; let mongoose = require('mongoose');
so it will not work.let mongoose, {Schema} = require('mongoose');
it's same aslet mongoose; let {Schema} = require('mongoose');
somongoose
is really undefined. – rie Commented May 1, 2017 at 20:27