Skip to main content
adicionou 99 caracteres ao conteúdo
Fonte Link
Cmte Cardeal
  • 7mil
  • 5
  • 27
  • 54

Em devdev roda sem erros, todos os tests tambem passam, consumindo a apiAPI tambem tudo normal, mas quando realizo o build com babel, o buldbuild é gerado com sucesso e ao executar node .\dist\index.js tenho este problema.

Obs: uso typeorm

Meu babel.config:

    module.exports = {
    presets: [
        [
            '@babel/preset-env',
            {
                targets: {
                    node: 'current'
                }
            }
        ],
        '@babel/preset-typescript'
    ],
    plugins: [
        "@babel/plugin-transform-async-to-generator",
        "babel-plugin-transform-typescript-metadata",
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        ["@babel/plugin-proposal-class-properties", { "loose": true }],
        [
            "@babel/plugin-transform-runtime",
            {
                "helpers": true,
                "regenerator": true
            }
        ]
    ],
    ignore: [
        '**/*.spec.ts'
    ]
}

}

Em dev roda sem erros, todos os tests tambem passam, consumindo a api tambem tudo normal, mas quando realizo o build com babel, o buld é gerado com sucesso e ao executar node .\dist\index.js tenho este problema.

Obs: uso typeorm

Meu babel.config:

module.exports = {
presets: [
    [
        '@babel/preset-env',
        {
            targets: {
                node: 'current'
            }
        }
    ],
    '@babel/preset-typescript'
],
plugins: [
    "@babel/plugin-transform-async-to-generator",
    "babel-plugin-transform-typescript-metadata",
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
    [
        "@babel/plugin-transform-runtime",
        {
            "helpers": true,
            "regenerator": true
        }
    ]
],
ignore: [
    '**/*.spec.ts'
]

}

Em dev roda sem erros, todos os tests tambem passam, consumindo a API tambem tudo normal, mas quando realizo o build com babel, o build é gerado com sucesso e ao executar node .\dist\index.js tenho este problema.

Meu babel.config:

    module.exports = {
    presets: [
        [
            '@babel/preset-env',
            {
                targets: {
                    node: 'current'
                }
            }
        ],
        '@babel/preset-typescript'
    ],
    plugins: [
        "@babel/plugin-transform-async-to-generator",
        "babel-plugin-transform-typescript-metadata",
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        ["@babel/plugin-proposal-class-properties", { "loose": true }],
        [
            "@babel/plugin-transform-runtime",
            {
                "helpers": true,
                "regenerator": true
            }
        ]
    ],
    ignore: [
        '**/*.spec.ts'
    ]
}
Fonte Link

Executar script compilado usando typescript + babel + typeorm

Ao tentar executar node .\dist\index.js compilado usando babel tenho o seguinte erro:

inserir a descrição da imagem aqui

Em dev roda sem erros, todos os tests tambem passam, consumindo a api tambem tudo normal, mas quando realizo o build com babel, o buld é gerado com sucesso e ao executar node .\dist\index.js tenho este problema.

Alguma dica do que estou fazendo errado?

Obs: uso typeorm

Meu babel.config:

module.exports = {
presets: [
    [
        '@babel/preset-env',
        {
            targets: {
                node: 'current'
            }
        }
    ],
    '@babel/preset-typescript'
],
plugins: [
    "@babel/plugin-transform-async-to-generator",
    "babel-plugin-transform-typescript-metadata",
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
    [
        "@babel/plugin-transform-runtime",
        {
            "helpers": true,
            "regenerator": true
        }
    ]
],
ignore: [
    '**/*.spec.ts'
]

}

Meu tsconfig:

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "commonjs",
    "lib": [
      "ES6"
    ],
    "allowJs": true,
    "rootDir": ".",
    "outDir": "./dist",
    "strict": false,
    "strictPropertyInitialization": false,
    "typeRoots": [
      "./node_module/@types",
      "./src/@types"
    ],
    "types": [
      "@types/jest"
    ],
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "removeComments": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": "./src"
  },
  "include": [
    "src/**/*"
  ]
}

Meu package:

{
  "name": "backend",
  "version": "1.0.0",
  "main": "index.js",
  "license": "ISC",
  "scripts": {
    "start": "node dist/index.js",
    "dev": "ts-node-dev -r tsconfig-paths/register --inspect --transpile-only --ignore node_modules src",
    "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
    "test": "cross-env NODE_ENV=test DB_DEFAULT=test jest --detectOpenHandles",
    "build": "rimraf ./dist && babel src --extensions \".js,.ts\" --out-dir dist --copy-files --no-copy-ignored"
  },
  "devDependencies": {
    "@babel/cli": "^7.13.10",
    "@babel/core": "^7.13.10",
    "@babel/plugin-proposal-class-properties": "^7.13.0",
    "@babel/plugin-proposal-decorators": "^7.13.5",
    "@babel/plugin-transform-async-to-generator": "^7.13.0",
    "@babel/plugin-transform-runtime": "^7.13.10",
    "@babel/preset-env": "^7.13.10",
    "@babel/preset-typescript": "^7.13.0",
    "@types/bcrypt": "^3.0.0",
    "@types/cors": "^2.8.10",
    "@types/express": "^4.17.11",
    "@types/express-boom": "^3.0.0",
    "@types/express-validator": "^3.0.0",
    "@types/jest": "^26.0.20",
    "@types/jsonwebtoken": "^8.5.0",
    "@types/morgan": "^1.9.2",
    "@types/node": "^14.14.31",
    "@types/nodemailer": "^6.4.0",
    "@types/rimraf": "^3.0.0",
    "@types/supertest": "^2.0.10",
    "@typescript-eslint/eslint-plugin": "^4.17.0",
    "@typescript-eslint/parser": "^4.17.0",
    "babel-plugin-transform-typescript-metadata": "^0.3.1",
    "cross-env": "^7.0.3",
    "eslint": "^7.21.0",
    "eslint-config-standard": "^16.0.2",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-node": "11.1.0",
    "eslint-plugin-promise": "4.2.1",
    "jest": "^26.6.3",
    "rimraf": "^3.0.2",
    "sqlite3": "^5.0.2",
    "supertest": "^6.1.3",
    "ts-jest": "^26.5.3",
    "ts-node-dev": "^1.1.6",
    "typescript": "^4.2.2"
  },
  "dependencies": {
    "bcrypt": "^5.0.1",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-boom": "^3.0.0",
    "express-validator": "^6.10.0",
    "generate-password": "^1.6.0",
    "helmet": "^4.4.1",
    "jsonwebtoken": "^8.5.1",
    "morgan": "^1.10.0",
    "mssql": "^6.3.1",
    "mysql2": "^2.2.5",
    "nodemailer": "^6.5.0",
    "typeorm": "^0.2.31"
  }
}