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

在Remix版Shopify Hydrogen应用中使用googleapis遇导出未定义等错误

问题描述
  • 仓库分支:feature/calendar-component
  • 场景:无法在Remix构建的Shopify Hydrogen应用的loader函数(位于app/routes/products.$handle.tsx第110行)中使用googleapis库

错误相关信息

引入代码(app/.server/googleCal.ts)

import {google} from 'googleapis';

npm run dev 报错信息

Warning: Could not find ts-node at /Users/hoge/prana-
 ›   cottage/node_modules/@shopify/cli/dist/index-e6f8190d.js.
 ›   Please ensure that ts-node is a devDependency. Falling back to
 ›    compiled source.
ReferenceError: exports is not defined
    at /Users/hoge/prana-cottage/node_modules/googleapis/build/src/index.js:15:23

对应报错行代码(googleapis/build/src/index.js:15:23):

Object.defineProperty(exports, "__esModule", { value: true });

npm run build 报错信息

RollupError: [commonjs--resolver] [plugin vite:resolve] Cannot bundle Node.js built-in "fs" imported
    from "node_modules/googleapis-common/build/src/discovery.js". Consider disabling ssr.noExternal or
    remove the built-in dependency.

无效的配置修改(vite.config.js)

ssr: {
    noExternal: ['fs', 'googleapis', 'googleapis-common'],
  },

其他问题表现

googleapis依赖包中的require语句无法正常工作,例如:

const fs = require("fs");

已尝试的解决方案

已尝试Stack Overflow上关于「Typescript ReferenceError: exports is not defined」的方案,以及vite-plugin-require插件,均未解决问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 20:49:56