Typescript找不到已安装的软件包Firebase

时间:2019-06-26 18:37:34

标签: typescript firebase npm

我有一个简单的打字稿项目,其中包含一堆.ts文件,我不会将它们编译为.js文件以用于其他项目。

在一个文件中,我需要软件包firebase,但似乎找不到该软件包。它已安装并位于node_modules文件夹中。当我这样做时:

import firebase from 'firebase';并运行tsc我得到

lib/api.ts:2:22 - error TS2307: Cannot find module 'firebase'.

2 import firebase from 'firebase';
                       ~~~~~~~~~~


Found 1 error.

我尝试删除node_modules文件夹以及package-lock.jsonnpm uninstall firebase,但似乎无济于事。

我的package.json:

{
  "name": "project-models",
  "version": "1.0.1",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "private": true,
  "scripts": {
    "build": "tsc",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Jonas Wallmann",
  "license": "ISC",
  "dependencies": {
    "firebase": "^6.2.3"
  },
  "devDependencies": {
    "typescript": "^3.5.2"
  }
}

我的tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
    "declaration": true,                   /* Generates corresponding '.d.ts' file. */
    "outDir": "./dist",                        /* Redirect output structure to the directory. */
    "strict": false,                           /* Enable all strict type-checking options. */
    "strictPropertyInitialization": false,  /* Enable strict checking of property initialization in classes. */
    "esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
  }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

也许类型定义文件没有嵌入在主要的npm包中。尝试从项目根目录运行npm install @types/firebase --save-dev,然后尝试再次编译。