hapijs / hapijs/hapi

Import error related to types in a new project

Open
#4,459 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.8k
Forks
1.4k
Avg merge
22d 3h
Merged PRs (30d)
1

Description

## context

While using the framework for the first time, I encountered a minor issue. It's not critical (in my case, I will simply install `joi`), but I thought you might want to be aware of it. Have a good day!

## reproduction

In a new node.js project:
- install @hapi/hapi
- create a server.ts file with the content:
```ts
import Hapi from "@hapi/hapi";

async function init() {
const server = Hapi.server({
port: 3000,
host: 'localhost'
});

await server.start();
console.log('Server running on %s', server.info.uri);
};

init();
```
- you get the following error:
```sh
> tsc

node_modules/@hapi/hapi/lib/types/route.d.ts:2:68 - error TS2307: Cannot find module 'joi' or its corresponding type declarations.

2 import { ObjectSchema, ValidationOptions, SchemaMap, Schema } from 'joi';
~~~~~

node_modules/@hapi/hapi/lib/types/server/server.d.ts:4:22 - error TS2307: Cannot find module 'joi' or its corresponding type declarations.

4 import { Root } from 'joi';
~~~~~

Found 2 errors in 2 files.

Errors Files
1 node_modules/@hapi/hapi/lib/types/route.d.ts:2
1 node_modules/@hapi/hapi/lib/types/server/server.d.ts:4
```

note : `npm i joi` resolves the error.

## a possible fix

https://github.com/hapijs/hapi/blob/23d65502a6cf5372f6db0acfaac9a5188b9050cd/lib/types/route.d.ts#L2

could it be?
```ts
import { ObjectSchema, ValidationOptions, SchemaMap, Schema } from '@hapi/validate';
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.