nextjs项目引入vconsole报错处理:ReferenceError: window is not defined

发布时间 2023-06-28 15:41:03作者: 猕猴桃姑娘

引入文件(nextjs项目):

import Vconsole from 'vconsole'

  

报错:

 

处理:

let Vconsole

if (typeof window !== 'undefined') {
  Vconsole = require('vconsole')
}

  

打开调试:

if (typeof window !== 'undefined') {
// 加了一个打开调试的条件 const debugConfig = /debug=1/g.test(location.href) if (debugConfig) { new Vconsole() } }

  

有问题欢迎交流,谢谢!