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

使用Yarn安装Next.js(含旧版本)时遇空字节错误求解决方案

解决Yarn创建指定版本Next.js应用时的null字节错误

问题背景

使用yarn create next-app@latest或yarn create next-app@12时触发错误:

An unexpected error occurred: "The property 'options.env['npm_config__p_a_c_k_a_g_e___l_o_c_k_']' must be a string without null bytes. Received '\x00t\x00r\x00u\x00e\x00'"

环境:Node 19.4.0、NPM 9.7.2、Yarn 1.22.19,且无版本指定的create-next-app codeswear可正常执行。


可行解决方案

  • 临时清除冲突环境变量
    问题源于NPM传入的带null字节的环境变量,Yarn 1.x无法处理,执行命令前先清除:

    # Linux/macOS
    unset npm_config__p_a_c_k_a_g_e___l_o_c_k_ && yarn create next-app@12
    
    # Windows PowerShell
    Remove-Item Env:npm_config__p_a_c_k_a_g_e___l_o_c_k_
    yarn create next-app@12
    
  • 改用NPM创建
    绕开Yarn的兼容问题,直接用NPM执行:

    npx create-next-app@12
    
  • 降级NPM版本
    NPM 9.x与Yarn 1.x的环境变量传递存在bug,降级到8.x稳定版:

    npm install -g npm@8.19.4
    

    降级后重新尝试Yarn的创建命令。

  • 升级Yarn到3.x
    Yarn 3.x对高版本Node兼容性更好,先升级Yarn:

    yarn set version berry
    

    再执行创建命令:

    yarn create next-app@12
    

内容的提问来源于stack exchange,提问作者Ayan Das Karmakar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 22:30:14