Help us understand the problem. What is going on with this article?

firebaseのRealtimeDatabaseをtypescriptでいじりたい(webpack + typescript + firebase_admin)

More than 1 year has passed since last update.

RealtimeDatabaseのデータをmigrationとかでいじりたいときあるっすよね。
想定してないデータができないようにルールを使うと思うんですが、
自分はtypescriptでルール通りに型をつくってデータを作成するようにすると安心できるので気に入ってます。

typescriptのコンパイルでwebpackを使ったんですが構成は下記みたいな感じ↓
https://github.com/chucker34/firebase_admin_pack

ちょっと詰まったところはwebpack.config.jsのresolve.mainFieldsmainを優先するようにしないとTypeError: rtdb.initStandalone is not a functionと怒られたこと。
俺たちのstackoverflowで同じように困っている人がいましたよと。
https://stackoverflow.com/questions/48266195/typeerror-rtdb-initstandalone-is-not-a-function
target: nodeにしてもブラウザ向けのファイルが使われていたのが原因。webpackだから普通そうなるけどね。

// webpack.config.js
const Dotenv = require('dotenv-webpack');

module.exports = {
  target: 'node',
  mode: 'development',
  entry: './src/main.ts',
  output: {
    path: `${__dirname}/dist`,
    filename: 'main.js'
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader'
      }
    ]
  },
  resolve: {
    extensions: [ '.ts', '.js', '.json' ],
    mainFields: ['main', 'module']
  },
  plugins: [
    new Dotenv()
  ]
};
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away