AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.03k stars 656 forks source link

TypeScript Issue with Set-up #1122

Closed araa47 closed 5 years ago

araa47 commented 5 years ago

Im currently setting up a simple typescript project using alasql.

Im using this as a template.

https://github.com/aleph-naught2tog/ts_without_dependencies

I first copied over the alasql.d.ts to src directory, then add the following to package.json

"typings": "src/alasql.d.ts",

Then my code looks like this.

import * as alasql from "alasql";

export function someFunction(): void {
  const body = document.getElementsByTagName("body")[0];
  body.style.backgroundColor = "lightblue";
}

export function dbInit(): void {

  alasql.parse("CREATE TABLE cities (city string, population number)");

  alasql.parse(
    "INSERT INTO cities VALUES ('Rome',2863223), ('Paris',2249975), ('Berlin',3517424),  ('Madrid',3041579)"
  );

  var res = alasql.parse(
    "SELECT * FROM cities WHERE population < 3500000 ORDER BY population DESC"
  );

  console.log(res);
}

However i seem to get the following error after compiling ts and running. The error can be seen on chrome console.

Uncaught TypeError: Failed to resolve module specifier "alasql". Relative references must start with either "/", "./", or "../".
mathiasrw commented 5 years ago

Sounds like you forgot to do a npm install alasql as it can not be found in node_modules.