Skip to content

Missing Documentation for making data-forge-fs work in TS environment. #186

@mwalkersigma

Description

@mwalkersigma

Node officially supports Typescript Syntax, but when attempting to use the TS FileSystem Example, I am guessing that since I am running it directly with node, instead of a compile step, I am hitting some kind of gotcha with modules.

Node Version: v24.10.0
Command: node index.ts

-=-=-=-=-=-=-=-=-
Example from docs
-=-=-=-=-=-=-=-=-

import * as dataForge from 'data-forge';
import 'data-forge-fs';

// 
// Create a simple data frame.
//
var values = dataForge
	.range(0, 14)
    .select(i => [i, Math.sin(i), Math.cos(i)]);
    
var dataFrame = new dataForge.DataFrame({
		columnNames: ["index", "Sin", "Cos"], 
		rows: values
	})
	.setIndex("index")
    .dropSeries("index");
    
console.log(dataFrame.skip(4).take(5).toString());

var series = dataFrame.getSeries("Sin");
console.log(series.skip(4).take(5).toString());

dataFrame.asCSV().writeFileSync("./test.csv");

const df2 = dataForge.readFileSync("./test.csv").parseCSV();
console.log("After save and load:");
console.log(df2.toString());

Gives the following error

const df2 = dataForge.readFileSync("./test.csv").parseCSV();
                      ^

TypeError: dataForge.readFileSync is not a function
    at file:///C:/<path>
    at ModuleJob.run (node:internal/modules/esm/module_job:377:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:691:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Node.js v24.10.0

This also happens when using current version of ts-node [10.9.2]

If I console.log dataForge, I can see two things one __esModule: true, and I can see that readFileSync is only exported under module.exports

now maybe I am doing something wrong, but I can only get type inference to work if I am using the typescript import, the require imports don't seem to accept types.

Is the recommended approach to compile the TS to JS ? since if I do tsc index.ts first everything works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions