我已經關注這個錯誤很長時間了,但我無法理解它。
這是代碼:
class Instance {
static {
}
}
module.exports = Instance;
這就是全部。這門課充滿了東西,但我把它們都洗掉了,因為它們無關緊要。無論有沒有它們,它都會給出相同的錯誤。
錯誤:
static {
^
SyntaxError: Unexpected token '{'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at Object.<anonymous> (path\to\project\index.js:1:18)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
我過去使用過靜態建構式并在其他地方測驗相同的代碼似乎有效,所以我不明白這里的問題是什么。請幫我。
解決方案:將 Node 更新到 16.13.1,現在可以使用了。16.7.0 還不夠。
uj5u.com熱心網友回復:
它由 Node 17.3.0 支持。這是一個 ES2022 特性。這個
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/387565.html
標籤:javascript 节点.js 班级 静止的
下一篇:是否可以將類實體用作C#中的值?
