2017-09-17 10 views
0

私はangular-cli(v 1.3.2)で設定した角度2/4アプリを持っています。私はSequel Proで見ることができるMAMPのmysqlサーバを稼働させています。モジュールが見つかりませんでした.All-CliでSequelizeを使用しました

sequelizeを使用して接続するには、getting started docsに従ってください。 (そして私は@types/sequelizeをインストールしました。)しかし、私はmysqlとpostgresの方言に対してModule not found: Error: Can't resolve...を得ています。ここで

は私のコードです:

import { Injectable } from '@angular/core'; 
import * as Sequelize from 'sequelize'; 

@Injectable() 
export class DataService{ 

    public sequelize: Sequelize.Sequelize; 

    constructor(){ 
    this.sequelize = new Sequelize('local-db', 'username', 'password', { 
     host: 'localhost', 
     dialect: 'mysql', 
     pool: { 
     max: 5, 
     min: 0, 
     idle: 10000 
     } 
    }); 
    this.init(); 
    } 

    public init(){ 
    this.sequelize.authenticate() 
     .then(() => { 
     console.log('Connection has been established successfully.'); 
     }) 
     .catch(err => { 
     console.log('Unable to connect to the database:'); 
     console.error(err); 
     }); 
    }; 
} 

たぶんWebPACKのは(ちょうどthis issueから推測)サードパーティのライブラリのいくつかの怠惰なロードされたリソース上でチョークのでしょうか?だから、私は私の.angular-cli.jsonで外部ライブラリとしてsequelizeを追加しました:

"scripts": [ 
    "../node_modules/sequelize/lib/sequelize.js" 
] 

しかし、私は同じエラーを取得しています:

ERROR in ./node_modules/sequelize/lib/dialects/mssql/query.js 
Module not found: Error: Can't resolve 'tedious' in '[MYAPPROOT]/node_modules/sequelize/lib/dialects/mssql' 
resolve 'tedious' in '[MYAPPROOT]/node_modules/sequelize/lib/dialects/mssql' 
    Parsed request is a module 
    using description file: [MYAPPROOT]/node_modules/sequelize/package.json (relative path: ./lib/dialects/mssql) 
    Field 'browser' doesn't contain a valid alias configuration 
    after using description file: [MYAPPROOT]/node_modules/sequelize/package.json (relative path: ./lib/dialects/mssql) 
    resolve as module 
     [MYAPPROOT]/node_modules/sequelize/lib/dialects/mssql/node_modules doesn't exist or is not a directory 
     [MYAPPROOT]/node_modules/sequelize/lib/dialects/node_modules doesn't exist or is not a directory 
     [MYAPPROOT]/node_modules/sequelize/lib/node_modules doesn't exist or is not a directory 
     [MYAPPROOT]/node_modules/node_modules doesn't exist or is not a directory 
yada 
yada 
yada 

私はsequelize接続マネージャに表示されます。 js、モジュールを見つけることが問題になる可能性があります。

if (err.code === 'MODULE_NOT_FOUND') { 
    throw new Error('Please install \'' + (sequelize.config.dialectModulePath || 'pg') + '\' module manually'); 
    } 

しかし、私はmysql2をインストールしています。

何が欠けていますか?この謎の助けがあれば大歓迎です!

答えて

1

「始めている」ドキュメントでは明示的に言っていませんが、node.jsアプリケーションを指しています。角度のないアプリケーションです。ほとんどの場合、角型アプリケーションからSQLに接続する必要はありません。あなたのデータベースに接続して、ある種のAPIを使ってそのアプリケーションと角度をつけて話す、「バックエンド」node.jsアプリケーションを作成する必要があります。

技術的には、角度からのmysqlにアクセスすることが可能ですが、それは必要になります。

  1. は角アプリケーションにログイン資格情報を置きます。誰でもあなたのアプリケーションを使っている人は
  2. のようにあなたの ブラウザのローカルホストです。つまり、ブラウザとデータベース が同じで動作している場合にのみ動作します機械。
関連する問題