Cannot find namespace 'SQLite'

I installed expo-sqlite with: expo install expo-sqlite
and then imported it with: import { SQLite } from 'expo-sqlite',

but I’m getting a “Cannot find namespace ‘SQLite’” warning in every instance of “SQLite” in my code.

Am I missing a step or something?

Hey @ken122624, what SDK version are you running?

I have expo 33.0.7.

Can you create a Snack that reproduces this error that I can try and replicate on my end? Also, is this occurring on iOS, Android or both?

Hi @ken122624. Can you try the following. If it does not give you any errors maybe you can compare it with your app to see what difference might be causing the problem:

Make sure expo-cli version 3.0.10 is installed.
Then create a new blank project with expo init sqlite-test.
This will set up a project with SDK 34, but you can change it back to SDK 33 as follows:

app.json:

{
  "expo": {
    "name": "sqlite-test",
    "slug": "sqlite-test",
    "privacy": "public",
    "sdkVersion": "33.0.0",
    "platforms": [
      "ios",
      "android"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    }
  }
}

package.json:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "^33.0.7",
    "react": "16.8.3",
    "react-dom": "^16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz"
  },
  "devDependencies": {
    "babel-preset-expo": "^6.0.0"
  },
  "private": true
}

If you run yarn and then expo diagnostics you should get something like this:

$ expo diagnostics

  Expo CLI 3.0.10 environment info:
    System:
      OS: ...
      Shell: 4.3.11 - /bin/bash
    Binaries:
      Node: 12.6.0 - /usr/local/node/bin/node
      Yarn: 1.17.3 - /usr/bin/yarn
      npm: 6.11.1 - /usr/local/node/bin/npm
    npmPackages:
      expo: ^33.0.7 => 33.0.7 
      react: 16.8.3 => 16.8.3 
      react-native: https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz => 0.59.8 
    npmGlobalPackages:
      expo-cli: 3.0.10

If you now expo install expo-sqlite and change App.js to the following, you should not get any errors:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { SQLite } from 'expo-sqlite';

const db = SQLite.openDatabase("db.db");

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

I’ve just tried the above and I did not get any errors. Let us know what happens when you try it.

I can give this a shot in a bit. Though I should of noted originally that I was seeing the errors in a Typescript project created with Expo. I tried creating a JS project and it actually seemed to have no issues.

1 Like

I found I was having some issues due to an “unknown” type declaration in SQLite.d.ts.

I upgraded Expo to 34.0.0, upgraded expo-sqlite to the compatible version, and then the SQLite.d.ts file no longer contained the “unknown” type declaration – resulting in my issues being resolved.

2 Likes

Happy to hear things are resolved on SDK34. Sorry you had to deal with the issue though. Thanks for bringing this up.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.