![](/img/trans.png)
[英]Typescripts, Jasmine -SyntaxError: Missing initializer in const declaration
[英]SyntaxError: Missing initializer in destructuring declaration
我在 Node.js 版本 6.9.5 上運行它
我有這個代碼:
let {Schema}, mongoose = require('mongoose');
這在理論上是一個簡化版本:
let mongoose = require('mongoose');
let Schema = mongoose.Schema;
我收到此錯誤:
let {Schema}, mongoose = require('mongoose');
^^^^^^^^
SyntaxError: Missing initializer in destructuring declaration
我嘗試了這個:
let mongoose, {Schema} = require('mongoose');
我得到了一個不同的錯誤,這是“貓鼬”未定義的結果。
我認為有可能做這樣的事情,我做錯了什么?
不。
let {Schema}, mongoose = require('mongoose');
它和
let {Schema};
let mongoose = require('mongoose');`
所以它不會工作,因為它不存在從中獲取Schema
對象。
let mongoose, {Schema} = require('mongoose');
它和
let mongoose;
let {Schema} = require('mongoose');`
mongoose
真的是未定義的。
對我來說,這是因為我返回的是空變量,所以我不得不檢查它們的值。 確保您返回正確的數據。
就我而言,這是因為語法。 使用node v18.7.0
和基本 JS(不是打字稿),我應該使用(用你的例子):
import mongoose, {Schema} = from 'mongoose';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.