我正在使用 next js 15 和 drizzle orm。我刚刚添加了毛毛雨并设置了样板,当我运行它时,我收到此错误。
错误:
GET /_next/static/webpack/f2b54d6051787b9b.webpack.hot-update.json 500 in 20249ms
⚠ Fast Refresh had to perform a full reload due to a runtime error.
GET /dashboard 500 in 12048ms
GET /favicon.ico 500 in 34ms
⨯ ./node_modules/pg-connection-string/index.js:76:1
Module not found: Can't resolve 'fs'
74 |
75 | // Only try to load fs if we expect to read from the disk
> 76 | const fs = config.sslcert || config.sslkey || config.sslrootcert ? require('fs') : null
| ^
77 |
78 | if (config.sslcert) {
79 | config.ssl.cert = fs.readFileSync(config.sslcert).toString()
https://nextjs.org/docs/messages/module-not-found
毛毛雨的数据库文件
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import { schema } from "@/schema";
import { env } from "@/config/env";
export const client = new Pool({
connectionString: env.DATABASE_URL,
});
export const db = drizzle(client, { schema, casing: "snake_case" });
毛毛雨配置文件
import { defineConfig, Config } from "drizzle-kit";
import "dotenv";
export default defineConfig({
dialect: "postgresql",
schema: "./schema/*",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
verbose: true,
strict: true,
out: "./drizzle/migrations",
casing: "snake_case",
} as Config);
我什至尝试将客户端从
pg
更改为postgress
,但我不断收到这些模块丢失错误(有时它显示net
模块丢失)。
像
fs
这样的模块只能在服务器端使用。 确保您没有从任何仅包含服务器端代码的文件导入客户端的任何内容。