Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use import statement outside a module #5632

Closed
TicTak21 opened this issue Oct 30, 2020 · 7 comments
Closed

Cannot use import statement outside a module #5632

TicTak21 opened this issue Oct 30, 2020 · 7 comments
Labels
needs triage This issue has not been looked into

Comments

@TicTak21
Copy link

TicTak21 commented Oct 30, 2020

Bug Report

Current behavior

yarn start or yarn start:dev

import { Entity, Column, PrimaryGeneratedColumn, Generated } from 'typeorm';
^^^^^^

SyntaxError: Cannot use import statement outside a module

Expected behavior

Build without errors

Environment

Nest version: 7.5.1

For Tooling issues:

  • Node version: 14.12.5
  • Platform: MacOS

Other:

package.json

{
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json",
    "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
    "typeorm:migration": "typeorm migration:create -d src/database/migrations/ -n",
    "typeorm:create-entity": "typeorm entity:create -d src/entities -n"
  },
  "dependencies": {
    "@nestjs/common": "^7.0.0",
    "@nestjs/core": "^7.0.0",
    "@nestjs/platform-express": "^7.0.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.5.4"
  },
  "devDependencies": {
    "@nestjs/cli": "^7.0.0",
    "@nestjs/config": "^0.5.0",
    "@nestjs/schematics": "^7.0.0",
    "@nestjs/testing": "^7.0.0",
    "@types/express": "^4.17.3",
    "@types/jest": "26.0.10",
    "@types/node": "^13.9.1",
    "@types/supertest": "^2.0.8",
    "@typescript-eslint/eslint-plugin": "3.9.1",
    "@typescript-eslint/parser": "3.9.1",
    "eslint": "7.7.0",
    "eslint-config-prettier": "^6.10.0",
    "eslint-plugin-import": "^2.20.1",
    "jest": "26.4.2",
    "pg": "^8.4.1",
    "prettier": "^1.19.1",
    "supertest": "^4.0.2",
    "ts-jest": "26.2.0",
    "ts-loader": "^6.2.1",
    "ts-node": "9.0.0",
    "tsconfig-paths": "^3.9.0",
    "typeorm": "^0.2.28",
    "typescript": "^3.7.4"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

ormconfig.ts

import { ConnectionOptions } from 'typeorm';

export const config: ConnectionOptions = {
  type: 'postgres',
  host: process.env.DB_HOST,
  port: parseFloat(process.env.DB_PORT),
  username: process.env.DB_USERNAME,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_DATABASE,
  entities: [__dirname + '/../**/*.entity{.ts,.js}'],
  migrations: ['dist/database/migrations/*.js'],
  synchronize: true,
};
@TicTak21 TicTak21 added the needs triage This issue has not been looked into label Oct 30, 2020
@jmcdo29
Copy link
Member

jmcdo29 commented Oct 30, 2020

Please use our Discord for support. We are using GitHub to track Bug Reports, Feature Requests, and Code Regressions.

@TicTak21
Copy link
Author

So I won't get an answer to my question here?

@jmcdo29
Copy link
Member

jmcdo29 commented Oct 30, 2020

You can search through our past issues too, this is something that seems to be common, and has already been answered. There's also this StackOverflow answer which has the exact same information.

@TicTak21
Copy link
Author

I have already tried these solutions.
But they don't work in my case.
The problem still exists.

@jmcdo29
Copy link
Member

jmcdo29 commented Oct 30, 2020

Please use our Discord for support. We are using GitHub to track Bug Reports, Feature Requests, and Code Regressions.

Then please follow our community standards and let's discuss this on Discord.

@TicTak21
Copy link
Author

Nice help.
"Thanks".

@TicTak21 TicTak21 reopened this Oct 30, 2020
@kamilmysliwiec
Copy link
Member

Please, use Discord for such questions. This isn't a bug but rather an issue that sits within your codebase (very likely related to an invalid glob pattern specified in the entities array in the ORM configuration).

@nestjs nestjs locked as too heated and limited conversation to collaborators Oct 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

3 participants