提问人:Saeesh Tendulkar 提问时间:10/19/2023 最后编辑:Saeesh Tendulkar 更新时间:10/20/2023 访问量:57
NodeJS ES6:用于私有类字段声明的意外字符“#”
NodeJS ES6: Unexpecter character '#' for private class field declaration
问:
我定义了一个带有私有类字段的类,如下所示
class BaseModel {
#database = null
}
export default BaseModel
但是当我尝试使用命令 npm start 使用 babel 编译它时,它给出了错误说
SyntaxError: src/helpers/BaseModel.js: 意外字符 '#' (5:1)
如果我尝试使用 Node 命令运行它
节点应用 .js
它有效。我的节点版本是 v18.17.1。 我如何让 babel 编译这个?
这是我package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "app.js",
"type": "module",
"scripts": {
"dev": "npx nodemon src/app.js",
"build": "npm run clean && npm run build-babel",
"start": "npm run build && node ./build/app.js",
"clean": "rm -rf build && mkdir build",
"build-babel": "babel -d ./build ./src -s",
"heroku-postbuild": "npm install && npm run build"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.23.2",
"@babel/register": "^7.22.15",
"axios": "^1.5.0",
"babel-preset-env": "^1.7.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"firebase-admin": "^11.10.1",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"mysql2": "^3.6.1",
"winston": "^3.10.0",
"winston-daily-rotate-file": "^4.7.1"
}
}
另外,这是我的 .babelrc
{
"presets": ["env"]
}
答: 暂无答案
评论
import "dotenv/config"
import "dotenv"; dotenv.config()
import