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

Palantir Foundry中引入tesseract.js-core遇'fs'模块解析错误求助

解决「Module not found: Error: Can't resolve 'fs'」问题求助

问题背景

在Palantir Foundry环境中开发,权限受限,仅能修改package.json、tsconfig.json及安装npm包。环境运行Node.js(v6至v8版本)、TypeScript和Webpack 4.46.0。最初尝试使用Tesseract.js实现OCR,但因Node版本过旧无法运行;改用tesseract.js-core封装成自定义npm包tmn-ocr安装后,编译时出现fs模块找不到的错误。

报错信息

ERROR in ./node_modules/tesseract.js-core/tesseract-core.js
Module not found: Error: Can't resolve 'fs' in '/scratch/job_directory/ri.jemma.main.job.00000004-a768-b479-8777-c7f527d6b225-278aba35-9de5-4bc1-acf3-7a286db52107/repo/functions-typescript/node_modules/tesseract.js-core'
    @ ./node_modules/tesseract.js-core/tesseract-core.js 11:72-85
    @ ./node_modules/tmn-ocr/tesser.js
    @ ./src/index.ts

当前配置

package.json

{
    "name": "my-functions",
    "version": "0.0.0",
    "description": "My useful functions",
    "main": "dist/index.js",
    "types": "dist/index.d.ts",
    "dependencies": {
        "@foundry/functions-api": "0.75.0",
        "@foundry/functions-typescript-runtime-internal-api": "0.62.0",
        "@foundry/functions-utils": "0.10.0",
        "tesseract.js": "4.0.6",
        "@types/node": "*",
        "tmn-ocr": "1.0.2"
    },
    "devDependencies": {
        "@foundry/functions-typescript-authoring-dev": "0.56.0",
        "@foundry/functions-typescript-ontology-code-generator": "0.75.0",
        "@foundry/functions-typescript-discovery": "0.66.0",
        "@foundry/functions-typescript-object-set-base": "1.59.0",
        "@foundry/functions-testing-lib": "0.50.0",
        "jest": "27.5.1",
        "ts-jest": "27.1.5"
    },
    "browser": {
        "fs": false,
        "os": false,
        "path": false
    },
    "scripts": {
        "build": "../gradlew build",
        "check": "../gradlew check",
        "test": "../gradlew test",
        "jest": "jest"
    },
    "license": "UNLICENSED"
}

tsconfig.json

{
    "compilerOptions": {
        "explainFiles": true,
        "declaration": true,
        "downlevelIteration": true,
        "module": "commonjs",
        "sourceMap": true,
        "moduleResolution": "node",
        "lib": [
            "esnext"
        ],
        "target": "es6",
        "outDir": "./dist",
        "removeComments": true,
        "preserveConstEnums": true,
        "experimentalDecorators": true,
        "strict": true,
        "skipLibCheck": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "types": [
            "node",
            "jest",
            "@foundry/functions-typescript-authoring-dev"
        ]
    },
    "include": [
        "*.ts",
        "**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "./node_modules/tesseract.js-core/tesseract-core.js"
    ]
}  

已尝试的方案

  • 在package.json的browser字段中设置"fs": false、"os": false、"path": false
  • 在tsconfig.json中启用skipLibCheck: true
  • 配置tsconfig的exclude规则排除node_modules及tesseract.js-core文件
  • 排查tsconfig的include/exclude配置逻辑

核心诉求

最终代码将在浏览器运行,仅需访问服务端路径,不需要读取客户端文件系统。目前考虑forktesseract.js-core修改以移除fs依赖,但不利于长期维护,希望找到其他可行方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 19:53:13