Using Sequelize ts (and perhaps other third party libraries)


#1

I have installed typings using npm install typings -g, then run typings install sequelize --ambient --save to install sequelize into my Ionic 2 project.

I cannot work out how I can import Sequelize into my app classes and use it!

If I try to do import * as Sequelize from 'sequelize' or import {Sequelize} from 'sequelize' I get the following build error…

Module build failed: Error: Cannot resolve module 'sequelize'

Would anyone be able to help me?

Thanks!


#2

Have you installed sequelize itself?

npm install --save sequelize


#3

Ah thanks! I hadn’t done that, but after I did it I still had more errors.

I still can’t properly get it working yet but I have also had to add { test: /\.json$/, loader: "json-loader" } to the loaders array in webpack.config.js because supposedly sequelize needed to use a package.json file, and also manually install other npm package dependencies which sequelize was looking for.

Also, running typings install sequelize --ambient --save gave the following output:

typings INFO reference Stripped reference "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/lodash/lodash.d.ts" during installation from "sequelize"
typings INFO reference Stripped reference "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/bluebird/bluebird.d.ts" during installation from "sequelize"
typings INFO reference Stripped reference "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/validator/validator.d.ts" during installation from "sequelize"
sequelize
└── (No dependencies)

which meant meant the sequalize typescript definitions file had errors. It looks like it’s typescript dependencies were ‘stripped’, so to fix it I had to install them all manually as well.

Does that always happen?


#4

So a few things here. Sequelize isn’t meant to be used client-side. It’s server side library for Node. So trying to use it in a Ionic2 app is not going to be possible.

As for the typings, this is apparently the way it’s supposed to work sadly :disappointed:


#5

Thanks for the reply, @mhartington!

I did not know this about Sequelize! I found it when I was looking for an ORM to use for a more complex Ionic app with a large database. Do you know of anything that has already been built that can plug in as an ORM? I thought Sequelize would work since it supports sqlite :disappointed:

And with the typings thing… Very annoying! ha. I tried the exact same install with tsd and it DOES install all dependencies. I’d have thought typings would do that same. Imagine if there were like 10 dependencies, you’d have to install them all manually, what a pain! ha


#6

I have just found https://github.com/coresmart/persistencejs which looks promising! I will have a look at implementing this at some point soon. The docs say it works with the sqlite cordova plugin and falls back on websql :slight_smile: