相关疑难解决方法(0)

在 Gatsby 构建期间检索文件内容

我需要提取程序源文件的内容,以便在 Gatsby 生成的页面中显示。我已经把所有东西都连接到了我应该可以打电话的地方

// my-fancy-template.tsx
import { readFileSync } from "fs";
// ...
const fileContents = readFileSync("./my/relative/file/path.cs");
Run Code Online (Sandbox Code Playgroud)

但是,在运行gatsby develop或 时gatsby build,出现以下错误

未找到此依赖项: ? * fs 在 ./src/templates/my-fancy-template.tsx 中?要安装它,您可以运行: npm install --save fs

但是,所有文档都表明该模块是 Node 原生的,除非它在浏览器上运行。我还不太熟悉 Node,但考虑到它gatsby build也失败了(这个命令甚至没有启动本地服务器),如果这是问题所在,我会有点惊讶。

我什至从一个新的测试站点 ( gatsby new test) 尝试了同样的效果。

node.js gatsby

4
推荐指数
1
解决办法
877
查看次数

标签 统计

gatsby ×1

node.js ×1