0

I cannot for the life of me figure out how to import readFileSync and writeFileSync from the rw module, specifically from its dash "submodule". I have tried the following

import {readFileSync, writeFileSync} from 'rw/dash';

which gives me error: Could not resolve "rw/dash". I can access the functions I need with import {dash} from 'rw'; and dash.readFileSync, but I'd rather import the functions directly. I also tried other things like

import {
  dash.readFileSync as readFileSync,
  dash.writeFileSync as writeFileSync
} from 'rw';

but dots don't seem to be allowed like this.

Any pointers are much appreciated. Or if this is against the "spirit" of javascript let me know.

1 Answer 1

1

If you don't mind adding a second line, you can do this:

import {dash} from 'rw';
const {readFileSync, writeFileSync} = dash;

The reason you can't import it with from 'rw/dash' is due to how that library does it's exports.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. What is it about the library that makes this not work? Is their implementation unorthodox somehow?
Not really, just very specific. index.js at the root of the project is the key. It explicitly exports each file, and in the case of lib/rw/dash.js, it also exports specific things. It was just a choice by the maintainer(s).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.