我试图在项目中使用顶层,看到有必要将模块从 tscofnig 更改为 esnext 或 system,但由于某种原因我的 ts-node 错误。而且我已经把 type: module 我试图使用标志:--experimental-modules 但错误仍然不知道如何解决。
包.json:
{
"name": "micro-hr",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"scripts": {
"commit": "git-cz",
"build": "babel src --extensions \".js,.ts\" --out-dir dist --copy-files --no-copy-ignored",
"start:dev": "ts-node-dev --experimental-modules --inspect --respawn --transpile-only --ignore-watch node_modules -r tsconfig-paths/register src/index.ts",
"start:debug": "node start --debug --watch",
"start:prod": "node dist/index.ts",
"test": "jest",
"lint": "eslint --fix",
"lint2": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config ./ormconfig.ts",
"migration:generate": "ts-node ./node_modules/typeorm/cli.js migration:generate -n"
},
"devDependencies": { …Run Code Online (Sandbox Code Playgroud) 您好,我有两个实体员工和部门,其中一个部门有 0 或 1 个经理\n我尝试添加一个没有经理的部门,但收到此错误:
\n\n\n错误:错误:列“manager_id”中的空值违反了非空\n约束
\n
我尝试添加一个只有名称但没有经理的部门\n我如何允许空值 \xe2\x80\x8b\xe2\x80\x8bin a fk
\n实体员工:
\n@Entity({ name: 'employees' })\nexport class Employee extends SharedProp {\n constructor(firstName: string, lastName: string) {\n super();\n this.firstName = firstName;\n this.lastName = lastName;\n }\n @PrimaryGeneratedColumn('uuid')\n id: string;\n\n @Column({ name: 'matricula', nullable: false })\n matricula: string;\n\n @Column({ name: 'first_name', nullable: false })\n firstName: string;\n\n @Column({ name: 'last_name', nullable: false })\n lastName: string;\n\n @Column()\n user_id: string;\n\n @Column()\n departament_id: string;\n\n @OneToOne(() => Departament, departament => departament.manager)\n @ManyToOne(\n () …Run Code Online (Sandbox Code Playgroud) 我在 input.value 和 input.length 上遇到此错误:
script.js:151 未捕获类型错误:无法读取未定义的属性“长度”
我正在尝试对输入应用货币掩码,但出现错误
function formatNumber(n) {
// format number 1000000 to 1,234,567
return n.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}
function formatCurrency(input, blur) {
// appends $ to value, validates decimal side
// and puts cursor back in right position.
// get input value
var input_val = input.value;
console.log(input)
// don't validate empty input
if (input_val === "") { return; }
// original length
var original_len = input_val.length;
// initial caret position
var caret_pos = input.getAttribute("selectionStart");
// check …Run Code Online (Sandbox Code Playgroud)我有这个 ormconfig.json:
{
"type": "postgres",
"host": "db-pg",
"port": 5432,
"username": "spirit",
"password": "api",
"database": "emasa_ci",
"synchronize": true,
"logging": false,
"entities": ["dist/src/entity/**/*.js"],
"migrations": ["dist/src/migration/**/*.js"],
"subscribers": ["dist/src/subscriber/**/*.js"],
"cli": {
"entitiesDir": "dist/src/entity",
"migrationsDir": "dist/src/migration",
"subscribersDir": "dist/src/subscriber"
}
}
Run Code Online (Sandbox Code Playgroud)
并有这个环境:
SERVER_PORT=4000
DB_HOST=db-pg
DB_PORT=5432
DB_USER=spirit
DB_PASS=api
DB_NAME=emasa_ci
Run Code Online (Sandbox Code Playgroud)
但是 .env 在 .json 中不起作用,所以我不知道我将如何在我的配置 orm 中使用我的环境变量