【问题标题】:Gridsome build failing with TypeErrorGridsome 构建失败并出现 TypeError
【发布时间】:2020-03-27 17:34:24
【问题描述】:

在启动项目模板上运行 Gridsome 构建时遇到了一些问题。该网站在localhost 上运行没有问题。我尝试npm install gridsome@latest 更新或安装任何丢失的软件包。

Gridsome build 给我以下错误:

    Could not generate HTML for "/work/":
    TypeError: Cannot read property 'console' of null
      at Object. (C:\Users\Micah\Desktop\my-gridsome-site\node_modules\vue-meta\dist\vue-meta.common.js:103:23)
      at Module._compile (internal/modules/cjs/loader.js:778:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
      at Module.load (internal/modules/cjs/loader.js:653:32)
      at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
      at Function.Module._load (internal/modules/cjs/loader.js:585:3)
      at Module.require (internal/modules/cjs/loader.js:692:17)
      at require (internal/modules/cjs/helpers.js:25:18)
      at C:\Users\Micah\Desktop\my-gridsome-site\node_modules\vue-server-renderer\build.prod.js:1:77671
      at Object. (webpack:/external "vue-meta":1:0)

vue-meta.common.js:103:23 处的代码为var console = _global.console || {};,如下所示:

var hasGlobalWindow = hasGlobalWindowFn();

var _global = hasGlobalWindow ? window : global;

var console = _global.console || {};
function warn(str) {
  /* istanbul ignore next */
  if (!console || !console.warn) {
    return;
  }

  console.warn(str);
}
var showWarningNotSupported = function showWarningNotSupported() {
  return warn('This vue app/component has no vue-meta configuration');
};

复制步骤

从命令行运行 gridsome 构建。

环境

System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
Binaries:
Node: 10.16.3 - C:\Program Files\nodejs\node.EXE
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.18362.449.0
npmPackages:
gridsome: ^0.7.11 => 0.7.11
gridsome-plugin-tailwindcss: ^2.2.26 => 2.2.26

【问题讨论】:

  • 你解决过这个问题吗?我在gridsome build 上也遇到了这个错误。我也在使用tailwindcss。
  • 我重新制作了项目并一一添加了包。我相信我在 vue-parallax-js 上失败了

标签: javascript vue.js typeerror gridsome vue-meta


【解决方案1】:

我认为问题仅出在构建中,因为您的组件使用了lack of SSR(服务器端渲染)。构建模式下没有窗口。尝试用 <ClientOnly> 标签将组件包装在 vue 的 <template> 标签中,如下所示:

<template>
  <ClientOnly>
    <my-component />
  </ClientOnly>
</template>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2013-12-05
    相关资源
    最近更新 更多