Skip to content

Could not find a declaration file for module 'ava'. 'node_modules/ava/entrypoints/main.mjs' implicitly has an 'any' type. #2934

Closed
@linaGirl

Description

@linaGirl

My test code is written in TypeScript but the type declarations cannot be found when using ava version 4. With ava version 3 it seems to work. This is probably due to the missing index.js file in the ava package?

Test file: tests/my.test.ts

import test from 'ava';

run:

node ./node_modules/.bin/tsc

output:

tests/my.test.ts:1:18 - error TS7016: Could not find a declaration file for module 'ava'. 'node_modules/ava/entrypoints/main.mjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/ava` if it exists or add a new declaration (.d.ts) file containing `declare module 'ava';`

1 import test from 'ava';
                   ~~~~~


Found 1 error in tests/my.test.ts:1

package.json

{
  "type": "module",
  "name": "test",
  "version": "1.0.0",
  "devDependencies": {
    "@ava/typescript": "^3.0.1",
    "@tsconfig/node16": "^1.0.2",
    "@types/node": "^17.0.5",
    "ava": "^4.0.0",
    "eslint": "^8.6.0",
    "typescript": "^4.6.0-dev.20220105"
  },
  "scripts": {
    "build": "node ./node_modules/.bin/tsc",
    "test": "node ./node_modules/.bin/tsc && ava"
  }
}

ava.config.js

export default {
    "typescript": {
        "rewritePaths": {
            "tests/": "build/tests/"
        },
        "compile": false
    }
}

tsconfig.json

{
  "extends": "@tsconfig/node16/tsconfig.json",
  "compilerOptions": {
    "preserveConstEnums": true,
    "outDir": "build",
    "strictPropertyInitialization": false,
    "target": "es2021",
    "module": "nodenext",
    "strict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "sourceMap": true,
    "declaration": true
  },
  "include": ["tests/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

Maybe i'm missing something. I'm happy to provide a repo for reproducing the problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions