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

Cannot find module 'lowdb/node' or its correspoing type declaractions #568

Closed
nulkode opened this issue Apr 22, 2023 · 4 comments
Closed

Comments

@nulkode
Copy link
Contributor

nulkode commented Apr 22, 2023

Code

import { Low } from 'lowdb'
import { JSONFile } from 'lowdb/node'
import { join } from 'path';
import { rootDir } from './constants';

const adapter = new JSONFile(
    join(rootDir, 'database', 'db.json')
);
const defaultData = { users: [] };
const db = new Low(adapter, defaultData);

export default db;

Packages

typescript: 5.0.4

Typescript config

{
      "compilerOptions": {
        "target": "ES2022",
        "module": "NodeNext",
        "moduleResolution": "node",
        "baseUrl": "./src",
        "sourceMap": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "skipLibCheck": true,
        "outDir": "./dist"
      },
      "include": ["src/**/*"]
}

Error message

$ tsc
src/lib/database.ts:2:26 - error TS2307: Cannot find module 'lowdb/node' or its corresponding type declarations.

Expected behaviour

The message should not be shown and the app should run.

@nulkode
Copy link
Contributor Author

nulkode commented Apr 22, 2023

I don't know if this is a duplicate of #554 but this has never happend to me before.

@typicode
Copy link
Owner

I think it's probably related to the config. I have a working app with lowdb v6, TS v5, node v19.9.0 and the following config:

{
  "extends": "@sindresorhus/tsconfig",
  "compilerOptions": {
    "incremental": true,
    "outDir": "./lib",
    "skipLibCheck": true
  }
}

If you can't change your config, you can have a look at the workaround in #554

BTW, it's because lowdb uses this https://nodejs.org/api/packages.html#subpath-exports

@typicode
Copy link
Owner

Many thanks for the PR 👍

@nulkode
Copy link
Contributor Author

nulkode commented Apr 29, 2023

I'm very happy to help.

This was my first time contributing to a serious open source project.

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

2 participants