0
drizzle-kit generate:pg --out migrations-folder --schema src/db/schema.ts

I run the above command to generate migration with drizzle but it give the below error

drizzle-kit: v0.19.12
drizzle-orm: v0.28.1

/media/chirag/DATA/Streaming Platform/node_modules/drizzle- 
orm/pg-core/index.mjs:1
import { n as TableAliasProxyHandler, N as PgColumnBuilder, e as 
entityKind, R as PgColumn, U as pgTableWithSchema, X as 
pgViewWithSchema, Y as pgMaterializedViewWithSchema, i as is } 
from '../alias-7164ff43.mjs';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1178:20)
at Module._compile (node:internal/modules/cjs/loader:1220:27)
at Module._extensions..js 
(node:internal/modules/cjs/loader:1310:10)
at Object.newLoader [as .mjs] (/media/chirag/DATA/Streaming 
Platform/node_modules/drizzle-kit/index.cjs:8608:13)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/media/chirag/DATA/Streaming 
Platform/src/db/schema.ts:1:49)

Below is my drizzle.config.json and packagejson

drizzle.config.json

{
  "out" : "./migrations",
  "schema" : "./src/db/schema.ts",
  "breakpoints" : false
}

package,json

{
 "name": "streaming-platform",
 "version": "0.0.1",
 "description": "",
 "main": "src/main.ts",
 "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon src/main.ts",
    "start": "ts-node src/main.ts",
    "build": "rimraf dist && tsc",
    "ts.check": "tsc --project tsconfig.json",
    "add-build": "git add dist",
    "migrate": "drizzle-kit generate:pg --out migrations-folder - 
      -schema src/db/schema.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
      "@consumet/extensions": "^1.4.18",
      "@fastify/cors": "^8.3.0",
      "@fastify/env": "^4.2.0",
      "@fastify/oauth2": "^7.2.2",
      "@fastify/swagger": "^8.8.0",
      "@fastify/swagger-ui": "^1.9.3",
      "dotenv": "^16.3.1",
      "drizzle-orm": "^0.28.1",
      "fastify": "^4.20.0",
      "fastify-plugin": "^4.5.1",
      "pg": "^8.11.2",
      "pg-pool": "^3.6.1",
      "pre-commit": "^1.2.2",
      "rimraf": "^5.0.1",
       "ts-node": "^10.9.1"
   },
   "devDependencies": {
      "@types/node": "^20.4.4",
      "@types/pg": "^8.10.2",
      "drizzle-kit": "^0.19.12",
     "typescript": "^5.1.6"
   },
   "pre-commit": [
      "ts.check",
      "build",
      "add-build"
   ]
}

I tried changing the package.json file and drizzle configs ans and also tried reinstalling the packages but the problem stays. I think its is some issue from my side but I am unable to figure that out

Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73
  • 1
    Does this answer your question? ["Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6](https://stackoverflow.com/questions/58211880/uncaught-syntaxerror-cannot-use-import-statement-outside-a-module-when-import) – Mushroomator Aug 08 '23 at 14:51
  • not sure the point of your drizzle.config.json if you're just going to add flags to `drizzle-kit generate:pg`. You can point to the config with `--config="/path/to/config"`. – Andrew Allen Aug 08 '23 at 14:58

0 Answers0