Skip to content

@tensorflow/tfjs-tfdf dist/tf-tfdf.fesm.js is using __dirname which breaks usage in esm project #8612

@kirillgroshkov

Description

@kirillgroshkov

Describe the current behavior

I am installing @tensorflow/tfjs-tfdf and importing it in an esm project (type=module in package.json).
I get an error that __dirname and __filename cannot be used in an esm project.

Describe the expected behavior

__dirname and __filename are not used in *.fesm.js artifacts.

Other info / logs

We are currently using a patch to mitigate it, but would be nice to fix it upstream:

diff --git a/dist/tf-tfdf.fesm.js b/dist/tf-tfdf.fesm.js
index d20fe1d4f3537dc638bbde5035b8a6db18a29e3c..33bdcb016342e7a0651670cef1c36a348be9d61c 100755
--- a/dist/tf-tfdf.fesm.js
+++ b/dist/tf-tfdf.fesm.js
@@ -16,6 +16,13 @@
  */
 import { registerOp, loadGraphModel, loadGraphModelSync } from '@tensorflow/tfjs-converter';
 import { scalar, tensor2d, tensor1d, io } from '@tensorflow/tfjs-core';
+import * as path from 'path'
+import * as fs from 'fs'
+
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+const __filename = fileURLToPath(import.meta.url)
+const __dirname = dirname(__filename)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions