Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I get a write error #4

Open
cherimo opened this issue Aug 11, 2024 · 5 comments
Open

I get a write error #4

cherimo opened this issue Aug 11, 2024 · 5 comments

Comments

@cherimo
Copy link

cherimo commented Aug 11, 2024

I use Nodejs v20.15.0

When I add the library I get the following issues:
Code:

import { PersistentNodeCache } from "persistent-node-cache";

const cache = new PersistentNodeCache("mycache", 1000);

cache.set("mykey", "myval", 1000);    //true

cache.get("mykey");

Error:

import { PersistentNodeCache } from "persistent-node-cache";
         ^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'PersistentNodeCache' not found. The requested module 'persistent-node-cache' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

Alternative is the following:
Code:

import pkg from 'persistent-node-cache';
const { PersistentNodeCache } = pkg;

const cache = new PersistentNodeCache("mycache", 1000);

cache.set("mykey", "myval", 1000);    //true

cache.get("mykey");

Error:

Error writing to file: [Error: EINVAL: invalid argument, write] {
  errno: -22,
  code: 'EINVAL',
  syscall: 'write'
}

Am I missing something? The permissions are set correctly.

@kwertop
Copy link
Owner

kwertop commented Aug 12, 2024

Hi @cherimo, could you please mention the OS that you're using? Also, a full error stack trace would be helpful.

@bpidperygora
Copy link

I'm encountering an issue on Ubuntu 22.04 while using Node.js v22.7.0 and npm v10.8.2. The error message I receive is:

Error writing to file: [Error: EINVAL: invalid argument, write] {
  errno: -22,
  code: 'EINVAL',
  syscall: 'write'
}

This error occurs during calls to the set() and del() methods. There are no specific traces or stack traces that point to the source of the error. I discovered the issue by systematically disabling modules and testing methods.

While this error doesn't seem to affect the functionality of my application, it's flooding my logs. This is the first time I've encountered this issue on a server running Express, and I'm using .mjs files.

Here is the relevant code snippet:

import pkg from 'persistent-node-cache';
const { PersistentNodeCache } = pkg;

let instance = null;

function getCacheInstance() {
  if (!instance) {
    instance = new PersistentNodeCache('token-cache');
    console.log('New cache instance created');
  } else {
    console.log('Returning existing cache instance');
  }
  return instance;
}

export default getCacheInstance;

And how it's being used:

import getCacheInstance from './tokenCache.mjs';
const cacheInstance = getCacheInstance();

cacheInstance.set(...);

Any insights or suggestions on how to resolve this issue would be greatly appreciated.

@kwertop
Copy link
Owner

kwertop commented Sep 4, 2024

Hi @bpidperygora,
Could you please show the output of the below script:

const {constants} = require('fs');

for (const k of Object.keys(constants).sort()) {
    const v = constants[k]
    if (v != null && typeof v !== "function" && typeof v !== "object") {
        console.log(k)
    }
}

@bpidperygora
Copy link

bpidperygora commented Sep 5, 2024

@kwertop

Hey. I told you that it does not affect functionality, but this is not true. I use your cache to manage tokens. And till the server running it's ok. But after reboot all tokens were gone. temporarily switch to Redis :(.

This one?:

COPYFILE_EXCL
COPYFILE_FICLONE
COPYFILE_FICLONE_FORCE
EXTENSIONLESS_FORMAT_JAVASCRIPT
EXTENSIONLESS_FORMAT_WASM
F_OK
O_APPEND
O_CREAT
O_DIRECT
O_DIRECTORY
O_DSYNC
O_EXCL
O_NOATIME
O_NOCTTY
O_NOFOLLOW
O_NONBLOCK
O_RDONLY
O_RDWR
O_SYNC
O_TRUNC
O_WRONLY
R_OK
S_IFBLK
S_IFCHR
S_IFDIR
S_IFIFO
S_IFLNK
S_IFMT
S_IFREG
S_IFSOCK
S_IRGRP
S_IROTH
S_IRUSR
S_IRWXG
S_IRWXO
S_IRWXU
S_IWGRP
S_IWOTH
S_IWUSR
S_IXGRP
S_IXOTH
S_IXUSR
UV_DIRENT_BLOCK
UV_DIRENT_CHAR
UV_DIRENT_DIR
UV_DIRENT_FIFO
UV_DIRENT_FILE
UV_DIRENT_LINK
UV_DIRENT_SOCKET
UV_DIRENT_UNKNOWN
UV_FS_COPYFILE_EXCL
UV_FS_COPYFILE_FICLONE
UV_FS_COPYFILE_FICLONE_FORCE
UV_FS_O_FILEMAP
UV_FS_SYMLINK_DIR
UV_FS_SYMLINK_JUNCTION
W_OK
X_OK

@aligzl
Copy link

aligzl commented Sep 6, 2024

Hi, i am using the same way ( storing the tokens ) and having same issue on cpanel hosting with nodejs.

Did you find Any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants