none
[Node.js][Mobile Apps] quickstart local debug cannot find sqlite3 RRS feed

  • Question

  • Hi, When I follow these steps I get "Cannot find module 'sqlite3'".

    I then 'npm install sqlite3' and still get trouble creating tables. Am I missing something?

    Here's cmd output:

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\josh>cd c:\source
    
    c:\Source>mkdir quickstart
    
    c:\Source>cd quickstart
    
    c:\Source\quickstart>git init
    Initialized empty Git repository in c:/Source/quickstart/.git/
    
    c:\Source\quickstart>npm init --yes
    This utility will walk you through creating a package.json file.
    It only covers the most common items, and tries to guess sane defaults.
    
    See `npm help json` for definitive documentation on these fields
    and exactly what they do.
    
    Use `npm install <pkg> --save` afterwards to install a package and
    save it as a dependency in the package.json file.
    
    Press ^C at any time to quit.
    name: (quickstart)
    version: (1.0.0)
    description:
    entry point: (index.js)
    test command:
    git repository:
    keywords:
    author:
    license: (ISC)
    About to write to c:\Source\quickstart\package.json:
    
    {
      "name": "quickstart",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "ISC"
    }
    
    
    Is this ok? (yes)
    
    c:\Source\quickstart>npm install express azure-mobile-apps --save
    npm WARN package.json quickstart@1.0.0 No description
    npm WARN package.json quickstart@1.0.0 No repository field.
    npm WARN package.json quickstart@1.0.0 No README data
    express@4.13.4 node_modules\express
    ├── array-flatten@1.1.1
    ├── escape-html@1.0.3
    ├── utils-merge@1.0.0
    ├── cookie-signature@1.0.6
    ├── merge-descriptors@1.0.1
    ├── methods@1.1.2
    ├── fresh@0.3.0
    ├── range-parser@1.0.3
    ├── vary@1.0.1
    ├── cookie@0.1.5
    ├── path-to-regexp@0.1.7
    ├── parseurl@1.3.1
    ├── content-type@1.0.1
    ├── etag@1.7.0
    ├── content-disposition@0.5.1
    ├── serve-static@1.10.2
    ├── depd@1.1.0
    ├── on-finished@2.3.0 (ee-first@1.1.1)
    ├── qs@4.0.0
    ├── finalhandler@0.4.1 (unpipe@1.0.0)
    ├── debug@2.2.0 (ms@0.7.1)
    ├── proxy-addr@1.0.10 (forwarded@0.1.0, ipaddr.js@1.0.5)
    ├── send@0.13.1 (destroy@1.0.4, statuses@1.2.1, ms@0.7.1, mime@1.3.4, http-error
    s@1.3.1)
    ├── accepts@1.2.13 (negotiator@0.5.3, mime-types@2.1.10)
    └── type-is@1.6.12 (media-typer@0.3.0, mime-types@2.1.10)
    
    azure-mobile-apps@2.1.0 node_modules\azure-mobile-apps
    ├── node-uuid@1.4.7
    ├── azure-odata-sql@0.0.2
    ├── es6-promise@3.1.2
    ├── winston@2.2.0 (cycle@1.0.3, stack-trace@0.0.9, eyes@0.1.8, isstream@0.1.2, p
    kginfo@0.3.1, async@1.0.0, colors@1.0.3)
    ├── azure-query-js@0.0.3 (esprima@2.7.2)
    ├── body-parser@1.15.0 (bytes@2.2.0, content-type@1.0.1, depd@1.1.0, on-finished
    @2.3.0, http-errors@1.4.0, raw-body@2.1.6, debug@2.2.0, qs@6.1.0, type-is@1.6.12
    , iconv-lite@0.4.13)
    ├── jsonwebtoken@5.7.0 (ms@0.7.1, xtend@4.0.1, jws@3.1.3)
    ├── azure-sb@0.10.2 (mpns@2.0.1, underscore@1.4.4, wns@0.5.3, azure-common@0.9.1
    6)
    └── mssql@3.2.1 (generic-pool@2.4.2, promise@7.1.1, tedious@1.14.0)
    
    c:\Source\quickstart>node --debug server.js
    debugger listening on port 5858
    
    module.js:340
        throw err;
              ^
    Error: Cannot find module 'sqlite3'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:280:25)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.<anonymous> (c:\Source\quickstart\node_modules\azure-mobile-apps\s
    rc\data\sqlite\connections.js:1:77)
        at Module._compile (module.js:456:26)
        at Object.Module._extensions..js (module.js:474:10)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:312:12)
        at Module.require (module.js:364:17)
    
    c:\Source\quickstart>npm install sqlite3 --save
    npm WARN package.json quickstart@1.0.0 No description
    npm WARN package.json quickstart@1.0.0 No repository field.
    npm WARN package.json quickstart@1.0.0 No README data
    /
    > sqlite3@3.1.3 install c:\Source\quickstart\node_modules\sqlite3
    > node-pre-gyp install --fallback-to-build
    
    [sqlite3] Success: "c:\Source\quickstart\node_modules\sqlite3\lib\binding\node-v
    11-win32-x64\node_sqlite3.node" is installed via remote
    sqlite3@3.1.3 node_modules\sqlite3
    └── nan@2.2.1
    
    c:\Source\quickstart>node --debug server.js
    debugger listening on port 5858
    2016-04-19T23:04:30.575Z - verbose: Adding table definition for TodoItem
    2016-04-19T23:08:44.191Z - debug: SQL statement failed - SQLITE_ERROR: no such t
    able: __types: SELECT [name], [type] FROM [__types] WHERE [table] = @table with
    parameters {"@table":"TodoItem"}
    2016-04-19T23:08:44.274Z - debug: SQL statement failed - SQLITE_ERROR: no such t
    able: TodoItem: SELECT * FROM [TodoItem] LIMIT 50 with parameters {}
    2016-04-19T23:08:52.642Z - debug: SQL statement failed - SQLITE_ERROR: no such t
    able: __types: SELECT [name], [type] FROM [__types] WHERE [table] = @table with
    parameters {"@table":"TodoItem"}
    2016-04-19T23:08:52.810Z - debug: SQL statement failed - SQLITE_ERROR: no such t
    able: TodoItem: INSERT INTO [TodoItem] ([text],[id]) VALUES (@text,@id); with pa
    rameters {"@text":"Test 3","@id":"60168c72-f0ec-4ab7-8898-013a8eb86014"}
    2016-04-19T23:08:52.819Z - info: Creating table TodoItem
    2016-04-19T23:08:52.824Z - debug: SQL statement failed - SQLITE_ERROR: no such t
    able: __types: SELECT [name], [type] FROM [__types] WHERE [table] = @table with
    parameters {"@table":"TodoItem"}
    2016-04-19T23:08:52.863Z - debug: SQL statement failed - SQLITE_ERROR: no such t
    able: __types: DELETE FROM [__types] WHERE [table] = @table with parameters {"@t
    able":"TodoItem"}

    The command prompt hangs on "verbose: Adding table definition for TodoItem"

    The later debug errors are logged when I try a GET-POST-GET all of which succeed in Postman.

    I was getting the same errors when trying to setup SQL Server for local offline dev like this.  So I stripped back to the simplest config and still the prob remains.

    TIA,

    Josh


    Tuesday, April 19, 2016 11:19 PM

Answers

  • Okay my problem was two-fold:

    First, I got SQLite because my azureMobile.js wasn't picked up, probably because of an error with the Winston stuff in Adrians blog .  Once I removed that, it worked fine.  Would've been nice to know the config file was found but an error occurred.

    Second, I was using '(local)\SQLEXPRESS' in the server name. 

    The following works for SQLEXPRESS as long as the instance is listening on TCP port 1433:

            data: {
                provider: 'mssql',
                server: 'localhost',
                database: 'nmobi_db',
                user: 'azuremobile',
                password: 'blah'
            }

    Now I can play with this in airplane mode.  Thanks for your help!

    Cheers,

    Josh

    • Marked as answer by joshbooker Wednesday, April 20, 2016 1:51 AM
    Wednesday, April 20, 2016 1:46 AM

All replies

  • Hi Josh,

    To use the sqlite data provider, you do need to install the sqlite3 npm package into your application. We did not include it by default to reduce deployment size and potential issues with the sqlite3 binary. Once you have installed the npm package, the app should run fine.

    Note that the SQL errors you are seeing are not fatal - they are a part of how the SDK decides to update the table schema as part of dynamic schema. We recognize that these are confusing and have cleaned up error logging for the next release (probably due next week).

    Hope this helps!

    Dale

    Wednesday, April 20, 2016 12:17 AM
  • Thanks Dale. Now I understand it's working as it should. I came to this after trying to get local offline sqlexpress to work. I added azureMobile.js with data:{...} but it was still complaining about sqlite3. Do you have a working example of this I could refer to. TIA, Josh
    Wednesday, April 20, 2016 12:25 AM
  • There is a reference and some examples in a pre-release piece of documentation - http://danderson00.github.io/azure-mobile-apps-node/module-azure-mobile-apps_configuration_Data%2520Providers.html

    We'll get this onto the main API reference documentation site very soon.

    Essentially, the sqlite provider is the default provider - to use the SQL Server provider, you need to add "provider: 'mssql'" to the data configuration. I know it's a little confusing that the default provider doesn't work without an extra install step - we'll reconsider this!

    Wednesday, April 20, 2016 12:40 AM
  • Thanks again. I tried that but it still fell back to SQLite. Would that be expected if the mssql fails? For local sql express instance perhaps I should try the options.instanceName like so data: { provider: 'mssql', server: 'localhost', database: 'myMobileAppDatabase', options: {instanceName: 'SQLEXPRESS'}, user: 'foo', password: 'bar' } What do you think? TIA, Josh
    • Edited by joshbooker Wednesday, April 20, 2016 12:51 AM
    Wednesday, April 20, 2016 12:50 AM
  • If you specify a provider value of 'mssql', it uses the SQL Server provider. If this is not provided, it will use the SQLite provider. There is no fallback.

    I am unsure if using instance names will be simple - pretty sure you'll need SQL Server Browser running for it to work. Alternatively, you can follow the directions at https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-node-backend-how-to-use-server-sdk/#howto-sqlexpress-setup to configure SQL Express.

    Wednesday, April 20, 2016 12:54 AM
  • Okay my problem was two-fold:

    First, I got SQLite because my azureMobile.js wasn't picked up, probably because of an error with the Winston stuff in Adrians blog .  Once I removed that, it worked fine.  Would've been nice to know the config file was found but an error occurred.

    Second, I was using '(local)\SQLEXPRESS' in the server name. 

    The following works for SQLEXPRESS as long as the instance is listening on TCP port 1433:

            data: {
                provider: 'mssql',
                server: 'localhost',
                database: 'nmobi_db',
                user: 'azuremobile',
                password: 'blah'
            }

    Now I can play with this in airplane mode.  Thanks for your help!

    Cheers,

    Josh

    • Marked as answer by joshbooker Wednesday, April 20, 2016 1:51 AM
    Wednesday, April 20, 2016 1:46 AM