hapijs / joi

The most powerful data validation library for JS
Other
20.91k stars 1.51k forks source link

Can not find module 'joi' after @hapi/joi installation #1845

Closed emclab closed 5 years ago

emclab commented 5 years ago

Context

What are you trying to achieve or the steps to reproduce ?

Installation of @hapi/joi failed to start. Removed Joi 13.x and installed @hapi/joi with yarn add @hapi/joi. Installation finished successfully. However node index.js throws error. yarn remove the module, delete the subdir joi and @hapi/joi under node-modules and reinstall @hapi/joi, the error is the same when launching the project.


const Joi = require('@hapi/joi');

#### Which result you had ?

internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module 'joi'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\d\code\js\emps_bbone\models\user.js:4:13)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

#### What did you expect ?
Should find the Joi module without problem
hueniverse commented 5 years ago

Other than to remove all deps and clean cache, I don’t have other advice. It clearly works for everyone else.

emclab commented 5 years ago

Upgraded node to 10.16.0 and the error is the same.

Marsup commented 5 years ago

It's likely your code is wrong, the stack trace clearly reads you explicitly require joi in your models/user.js file. I'd look that way.

yadynesh commented 4 years ago

I am facing the same issue. @emclab How did you resolve it?

noguntuberu commented 4 years ago

I have the same issue

yadynesh commented 4 years ago

I have the same issue

Just install this types package https://www.npmjs.com/package/@types/hapi__joi

noguntuberu commented 4 years ago

I discovered my issue arose from having installed the most recent nodejs version (13>).

I solved it by updating npm. Run npm install -g npm.

thirdink commented 4 years ago

I had the same problem and I found out that i had another dependency that required 'joi' instead of '@hapi/joi'.

umangbista2 commented 4 years ago

I had the same problem and I found out that i had another dependency that required 'joi' instead of '@hapi/joi'.

How to find that "another dependency"? @thirdink

Marsup commented 4 years ago

npm ls joi or yarn why joi depending on which you use.

taimoorgit commented 4 years ago

This took me a very long time to debug. In one faraway file I had imported @hapi/Joi (notice the capital J rather than @hapi/joi (lowercase j)

taimoorgit commented 4 years ago

Make sure you are doing require("@hapi/joi") with lowercase letters!

dhanja1999 commented 4 years ago

Install it globally... npm i -g @hapi/joi

Marsup commented 4 years ago

Yeah no, don't ever do that.

dhanja1999 commented 4 years ago

Yeah no, don't ever do that.

Why? I resolved the same issue by doing that.

Marsup commented 4 years ago

Because the same version is installed system wide, that's not how you deal with node projects.

divyarajsinhchampavat commented 2 years ago

Just

You Are Right bro @yadynesh

nicolasmarino99 commented 1 year ago

I have the same issue

Just install this types package https://www.npmjs.com/package/@types/hapi__joi

For me worked: npm i @types/joi

Nargonath commented 1 year ago

@nicolasmarino99 joi ships its own types: https://github.com/hapijs/joi/blob/master/lib/index.d.ts (at least in recent versions). You shouldn't have to install types from DefinitelyTyped if you use latest version.