Pg - Next js 15 模块未找到:无法解析“fs”

问题描述 投票:0回答:1

我正在使用 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
模块丢失)。

node.js typescript postgresql next.js drizzle
1个回答
0
投票

fs
这样的模块只能在服务器端使用。 确保您没有从任何仅包含服务器端代码的文件导入客户端的任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.