nuxt-hub / core

Build full-stack applications with Nuxt on CloudFlare, with zero configuration.
https://hub.nuxt.com
Apache License 2.0
937 stars 53 forks source link

Deploy failed — Cannot resolve "drizzle-orm/d1/migrator" #171

Closed lammerfalcon closed 3 months ago

lammerfalcon commented 3 months ago

Describe the bug Failed to deploy when using drizzle orm. May be i miss something? but i check many times drizzle setup flow and didnt get how to deploy) plugins/migration.ts

import { consola } from 'consola'
import { migrate } from 'drizzle-orm/d1/migrator'

export default defineNitroPlugin(async () => {
  if (!import.meta.dev) return

  onHubReady(async () => {
    await migrate(useDrizzle(), { migrationsFolder: 'server/database/migrations' })
      .then(() => {
        consola.log('Database migrations done')
      })
      .catch((err) => {
        consola.error('Database migrations failed', err)
      })
  })
})

if i remove migrations - there another error in utils

import { drizzle } from 'drizzle-orm/d1' <- cannot resolve drizzle
import * as schema from '../database/schema'

export { sql, eq, and, or } from 'drizzle-orm'

export const tables = schema

export function useDrizzle() {
  return drizzle(hubDatabase(), { schema })
}

export type User = typeof schema.users.$inferSelect

Steps to reproduce Steps to reproduce the behavior:

  1. Step by step setup drizzle orm from NuxtHub doc
  2. Run db:generate and check thats drizzle works locally - can create new user, get users list
  3. Push to repo and check deployment flow

Expected behavior there some error from deployment logs

12:00:35.899 [info] [nitro] Building Nuxt Nitro server (preset: `cloudflare-pages`)
12:00:36.410 [error] [nitro] Error: Cannot resolve "drizzle-orm/d1/migrator" from "/opt/buildhome/repo/server/plugins/migrations.ts" and externals are not allowed!
12:00:36.411 
12:00:36.411 
12:00:36.411 undefined
12:00:36.413 [error] Cannot resolve "drizzle-orm/d1/migrator" from "/opt/buildhome/repo/server/plugins/migrations.ts" and externals are not allowed!
12:00:36.413   at Object.resolveId (node_modules/.pnpm/nitropack@2.9.6_@opentelemetry+api@1.8.0/node_modules/nitropack/dist/nitro.mjs:1966:17)
12:00:36.413   at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:19674:28)
12:00:36.413   at async resolveId (node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:18355:26)
12:00:36.413   at async ModuleLoader.resolveId (node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:18758:15)
12:00:36.414   at async Object.resolveId (node_modules/.pnpm/@rollup+plugin-commonjs@25.0.8_rollup@4.18.0/node_modules/@rollup/plugin-commonjs/dist/es/index.js:588:10)
12:00:36.414   at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:19674:28)
12:00:36.414   at async resolveId (node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:18355:26)
12:00:36.414   at async ModuleLoader.resolveId (node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:18758:15)
12:00:36.414   at async node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:19062:50 
12:00:36.414 
12:00:36.414 [error] Cannot resolve "drizzle-orm/d1/migrator" from "/opt/buildhome/repo/server/plugins/migrations.ts" and externals are not allowed!
12:00:36.581 Failed: Error while executing user command. Exited with error code: 1
12:00:36.592 Failed: build command exited with code: 1
12:00:38.307 Failed: error occurred while running build command
lammerfalcon commented 3 months ago

alsonpx nuxi dev --remoteworks fine, but deploy failed

image image
lammerfalcon commented 3 months ago

Omg. Sorry for issue) my package.json miss drizzle-orm package... -4 hours of life) but now i know NuxtHub under the hood

atinux commented 3 months ago

No worries @lammerfalcon 😃