You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js中@node-rs/argon2模块找不到问题求助

解决@node-rs/argon2模块找不到的问题

针对你在Next.js 15.0.0-rc.0中使用@node-rs/argon2遇到的模块找不到错误,尝试以下方案:

  • 强制重新安装适配平台的依赖
    删除现有依赖和锁文件,清理缓存后重新安装,确保native模块匹配当前系统架构:

    # 根据你的包管理器选择对应命令
    # npm
    rm -rf node_modules package-lock.json
    npm cache clean --force
    npm install
    
    # pnpm
    rm -rf node_modules pnpm-lock.yaml
    pnpm store prune
    pnpm install
    
    # yarn
    rm -rf node_modules yarn.lock
    yarn cache clean
    yarn install
    
  • 验证Node.js架构匹配
    错误中模块路径是win32-x64-msvc,确保你的Node.js是x64架构:

    node -p process.arch
    

    如果输出是ia32,请卸载当前Node.js,重新安装x64版本。

  • 安装Windows构建依赖
    @node-rs/argon2是Rust编译的native模块,Windows下需要Visual Studio构建工具支持:

    1. 安装Visual Studio Installer
    2. 勾选「使用C++的桌面开发」workload,确保包含Windows SDK组件
    3. 安装完成后重启终端,重新安装依赖
  • 调整Next.js配置(针对RC版本兼容性)
    Next.js 15 RC版本可能存在配置兼容性问题,尝试扩展配置项:

    /** @type {import('next').NextConfig} */
    const nextConfig = {
      serverExternalPackages: ['@node-rs/argon2', '@node-rs/argon2-win32-x64-msvc'],
      experimental: {
        serverExternalPackages: ['@node-rs/argon2']
      }
    };
    
    export default nextConfig;
    
  • 临时切换纯JS哈希库
    如果以上方案都无效,可以暂时改用纯JS实现的argon2库替代,比如argon2:

    npm uninstall @node-rs/argon2
    npm install argon2
    

    然后在Lucia配置中替换哈希函数:

    import argon2 from "argon2";
    import { lucia } from "lucia";
    
    const auth = lucia({
      // ...其他配置
      passwordHash: {
        generate: async (password) => {
          return argon2.hash(password);
        },
        verify: async (hash, password) => {
          return argon2.verify(hash, password);
        }
      }
    });
    

内容的提问来源于stack exchange,提问作者Ustin Drazhin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 04:17:36