我正在尝试最新的Firebase npm模块(4.8.1
)。我正在使用带有webpack捆绑的commonjs模块系统。为了确保我得到我需要的打字,我在package.json
:
"dependencies: {
"firebase": "^4.8.1"
},
"devDependencies": {
"@firebase/app": "^0.1.5",
"@firebase/app-types": "^0.1.0",
"@firebase/auth": "^0.3.1",
"@firebase/auth-types": "^0.1.0",
"@firebase/database": "^0.1.6",
"@firebase/database-types": "0.1.0",
}
当我使用tsc
进行转换时,我收到以下错误:
node_modules/@firebase/database/dist/esm/src/api/Database.d.ts(4,33):错误TS2307:找不到模块'@ firebase / app-types / private'。
node_modules/@firebase/database/dist/esm/src/core/AuthTokenProvider.d.ts(179):error TS2307:找不到模块'@ firebase / app-types / private'。
我发现这很奇怪有几个原因:
@firebase/data-types
是提供 typings 而不是实现代码。这就是为什么我把它列为 devDependency 而不是依赖 @firebase/*
切换为“依赖关系”,它仍然会给出相同的错误答案 0 :(得分:1)
使用以下tsconfig.json
它对我来说很好用:
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"moduleResolution": "node",
"inlineSourceMap": true
}
}
在src/index.ts
我只是这样导入:
// This import loads the firebase namespace along with all its type information.
import * as firebase from 'firebase';
const firebaseApp = firebase.initializeApp({
apiKey: '<your-api-key>',
authDomain: '<your-auth-domain>',
databaseURL: '<your-database-url>',
storageBucket: '<your-storage-bucket>',
messagingSenderId: '<your-sender-id>'
});
在我修改tsconfig.json
之前,我遇到了类似的问题:
{
...
"devDependencies": {
...
},
"dependencies": {
...,
"firebase": "^4.8.1"
}
}
我希望有所帮助!