I installed #nestjs/mongoose with following npm command:
npm i --save #nestjs/mongoose mongoose
But when I try to lauch the app, I get following errors:
node_modules/#nestjs/mongoose/dist/decorators/prop.decorator.d.ts:2:44 - error TS2694: Namespace '"mongoose"' has no exported member 'SchemaTypeOpts'.
export declare type PropOptions = mongoose.SchemaTypeOpts<any> | mongoose.Schema | mongoose.SchemaType;
~~~~~~~~~~~~~~
node_modules/#nestjs/mongoose/dist/factories/schema.factory.d.ts:4:60 - error TS2315: Type 'Schema' is not generic.
static createForClass<T = any>(target: Type<unknown>): mongoose.Schema<T>;
~~~~~~~~~~~~~~~~~~
node_modules/#nestjs/mongoose/dist/interfaces/mongoose-options.interface.d.ts:3:10 - error TS2305: Module '"mongoose"' has no exported member 'ConnectionOptions'.
import { ConnectionOptions } from 'mongoose';
~~~~~~~~~~~~~~~~~
Found 3 error(s).
Any help would be highly appreciated.
Revert your mongoose install down to 5.10.x. The latest version of mongoose came out with their own set of types, which ended up breaking a lot of things: Reference Issue
The best combination that worked for me is the following.
"#nestjs/mongoose": "^7.0.4",
"mongoose": "^5.10.19",
"#types/mongoose": "^5.10.3", //dev-dependency
As of 19 Dec 2020, any version later than that did NOT work for me.
As mentioned here, the best thing to do is to upgrade:
"#nestjs/mongoose": "^7.2.0",
"mongoose": "^5.11.5",
It might be better to remove those dependencies and run npm install --save #nestjs/mongoose mongoose again
Also remove #types/mongoose": ^5.10.2" if you have that.
Since mongoose v5.11.x, the module exposes it's own file definition and can break your build!
To solve it, install #tsed/mongoose and remove the #types/mongoose dependencies.
Run the following commands:
npm i --save #nestjs/mongoose mongoose
npm i --save-dev #tsed/mongoose
And make sure you've removed #types/mongoose
try the following versions. it was worked for me.
"#nestjs/mongoose" - "^9.2.0"
"mongoose" - "^6.6.3"
Related
When I try to compile my Typescript project (NestJS) I came across the following problem.
Some packages like nanoid, cookie-parser give error Error: Cannot find module 'nanoid'
The code where they used is below:
...
import { nanoid } from "nanoid";
...
const confirmToken = nanoid(32);
...
Here are what I tried:
I checked the node_modules directory. The package is there
Tried to completely remove node_modules and package.json.lock.
Used v16.14.0, v17 versions of NodeJS
Used yarn and npm
None of these ways helped.
Again, this error happens with only certain packages.
What could be an issue?
I have created a new project, installed few type definitions (from DefinitelyTyped) and made a basic src/go.ts file.
Whenever I transpile the code, I get a ton of TS2304: Cannot find name 'Promise' errors!
The ./typings/mongodb/index.d.ts is referencing the Promise, but the compiler does not seem to find that.
Please note that I have dt~promise installed as well.
Screenshot (Errors on the left side, type definitions installed and the app code are on the right)
Content of typings.json:
{
"globalDependencies": {
"dotenv": "registry:dt/dotenv#2.0.0+20160327131627",
"express": "registry:dt/express#4.0.0+20160708185218",
"express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160805091045",
"mime": "registry:dt/mime#0.0.0+20160316155526",
"mongodb": "registry:dt/mongodb#2.1.0+20160602142941",
"mongoose": "registry:dt/mongoose#4.5.4+20160807120805",
"mongoose-promise": "registry:dt/mongoose-promise#4.5.4+20160720003345",
"node": "registry:dt/node#6.0.0+20160807145350",
"promise": "registry:dt/promise#7.1.1+20160602154553",
"serve-static": "registry:dt/serve-static#0.0.0+20160606155157"
}
}
Any thoughts?
I've experienced the same issue (more or less, using #types instead of typings) and was able to solve it by installing the type definitions for CoreJS.
Screenshots
Apologize for linking to a library, this is my first post so I am unable to provide more than two links per post.
Image explanations:
First screenshot shows similar error, type definition file for MongoDB is unable to find 'Promise'.
Install type definitions for CoreJS. Note that I am getting my type definitions through NPM and not Typings. So to do something similar in Typings you would run something like:
typings install dt~core-js --save --global
Third screenshot shows build command with no errors on output 😁
I hope this resolves your issue.
I had the same issue installing lastest version of mongodb and mongoose typings.
The new definition file for mongodb assumes you are using ES6 promise so if you change the target of the typescript compiler in the tsconfig.json to es6 it should do the trick :
tsconfig.json:
{
"compilerOptions": {
...
"target": "ES6",
...
}
}
For typings: typings install core-js --ambient --save.
It works for me.
I am trying to use pouchdb with Typescript. I cannot link to the pouchdb module.
import { PouchDB } from "pouchdb"
reports that it cannot find module pouchdb, even though it is in node_modules.
I also cannot find the appropriate typings for pouchdb.
I'm doing this in Ionic, so I may be missing a step on getting the types file loaded properly.
Make sure your types are installed with:
npm install --save-dev #types/pouchdb
At the top of your data service import pouch like so:
import * as PouchDB from 'pouchdb';
* edit *
I don't have all the facts, but this is my current understanding.
Typings is no longer needed in Typescript >2.0
I believe typescript now works automatically with types files installed from DefinitelyTyped.
DefinitelyTyped is an official central repository that is kept current like npm.
And even if I'm dead wrong about all this, DefinitelyTyped is still better than typings and has a much bigger community.
Cause i just had this Problem, For Angular 2 + Typescript the correct way to use PouchDB (using angular-cli) is to:
ng new SOMENAME
npm install --save pouchdb
npm install --save-dev #types/pouchdb
In your app.component import PouchDB from 'pouchdb';
In your App Component Class public db: any; and to init this.db = new PouchDB('test'); // , {storage:'persistent'} not working in typescript without updating typings
see https://github.com/nolanlawson/pouchdb-find/issues/201.
If you have problems installing the packages on windows with an EPERM Error use (f.e.) npm install --save pouchdb --no-optional to disable the warning. The installation should still be ok. For more info see https://github.com/npm/npm/issues/17671
I had the same problem trying to import into Angular 6.
Your imports seem fine:
import PouchDB from 'pouchdb';
import PouchFind from 'pouchdb-find';
PouchDB.plugin(PouchFind);
What you may be missing is you need to add this to your polyfills.ts file:
(window as any).global = window;
(window as any).process = {};
(window as any).process.nextTick = setTimeout;
import PouchDB from 'pouchdb';
export abstract class PouchDBDatabase {
private _database: PouchDB.Database<Sheet>;
constructor(protected DATABASE_URL: string) {
this._database = new PouchDB(this.DATABASE_URL);
}
}
And you're good to go with typescript + pouchDB :)
I managed to get the module recognised by using
declare function require(a)
var PouchDB = require("pouchdb")
I have given up type checking, but at least I can make progress.
I am currently trying to develop an app using Ionic 2 and Angular 2 with Typescript version. I decided to use the library amqp-ts to include messaging in my app. I installed the library via npm like:
npm install amqp-ts
Everything went fine and now I've got something like this:
/ app root directory
+ node_modules
- amqp-ts
- lib
- amqp-ts.d.ts
- node_modules
- amqplib
- bluebird
- winston
The problems begin now: I import the library into my component as it is done in the example of the documentation...
import * as Amqp from "amqp-ts";
... and when I try to deploy the app I get the next error messages:
TypeScript error: C:/APPs/Test/Ionic2Angular2App/node_modules/amqp-ts/lib/amqp-ts.d.ts(2,26): Error TS2307: Cannot find module 'bluebird'.
TypeScript error: C:/APPs/Test/Ionic2Angular2App/node_modules/amqp-ts/lib/amqp-ts.d.ts(50,12): Error TS2304: Cannot find name 'Buffer'.
1. The line related to the first error message
// exported Typescript type definition for AmqpSimple
import * as Promise from "bluebird";
[...]
2. The line related to the second error message (same file: amqp-ts.d.ts)
export class Message {
content: Buffer;
[...]
}
I hope you can help me, please.
Additionally to regular package install you need to install TypeScript typings. Typings are like header files, they contain all methods/classes/interfaces definitions.
To install typings you need a typings tool. The best way is to install it globally so you can use it in every project
npm install typings --global
Then installing new typings inside your project is pretty simple, first search for library:
typings search bluebird
Install it :
typings install --save bluebird
More info : https://github.com/typings/typings
I too faced same issue, but for me above answer is not working.
While simply running :
npm i bluebird
resolving the issue
When requiring sequelize I get some warning about "Critical dependencies".
After running the app I get the following error: "Error: The dialect postgres is not supported. (Error: Please install 'pg' module manually)".
Both pg and pg-hstore are however installed.
I think the problem is with sequelize.js dynamically looking for postgres. I tried to use the webpack ContextReplacementPlugin, but I have no idea how.
I'm using the React Starter Kit boilerplate. The code that causes the problem is nothing more than this:
var Sequelize = require('sequelize');
//get the database info
import { dbModelLocation} from '../config';
import { dbConnectionConfig } from '../config';
var sequelize = new Sequelize(dbConnectionConfig.name,
dbConnectionConfig.user,
dbConnectionConfig.pass,
dbConnectionConfig.options);
The exact warnings I get from webpack are:
WARNING in ./~/sequelize/lib/sequelize.js Critical dependencies:
636:60-73 the request of a dependency is an expression #
./~/sequelize/lib/sequelize.js 636:60-73
WARNING in ./~/sequelize/lib/dialects/mssql/connection-manager.js
Critical dependencies: 15:15-71 the request of a dependency is an
expression # ./~/sequelize/lib/dialects/mssql/connection-manager.js
15:15-71
WARNING in ./~/sequelize/lib/dialects/mysql/connection-manager.js
Critical dependencies: 15:15-69 the request of a dependency is an
expression # ./~/sequelize/lib/dialects/mysql/connection-manager.js
15:15-69
WARNING in ./~/sequelize/lib/dialects/postgres/connection-manager.js
Critical dependencies: 16:41-92 the request of a dependency is an
expression 16:102-153 the request of a dependency is an expression #
./~/sequelize/lib/dialects/postgres/connection-manager.js 16:41-92
16:102-153
WARNING in ./~/sequelize/lib/dialects/sqlite/connection-manager.js
Critical dependencies: 19:15-71 the request of a dependency is an
expression # ./~/sequelize/lib/dialects/sqlite/connection-manager.js
19:15-71
If you're like me ran into the same issue when using Webpack with Sqlite3 or MySQL, you'll need to use externals and define the dependencies:
var config = {
externals: ['pg', 'sqlite3', 'tedious', 'pg-hstore'],
};
Further information can be found in the following:
Can't resolve pg-hstore
Webpack externals
Sorry for answer on old questions, but I got the same error when I tried to use sequelize migrations. May be it will help someone.
You have to install 'pg' package globally and it will be work:
npm install -g pg
According to the Webpack author the solution is to ignore node_modules while bundling.