【问题标题】:Using Firebase in Node Server Typescript File在节点服务器 Typescript 文件中使用 Firebase
【发布时间】:2018-11-26 20:12:09
【问题描述】:

• 我最近在我的应用程序中使用 Angular Universal 实现了服务器端渲染。

• 这需要将我的节点服务器文件从 .js 转换为 .ts。

• Typescript 使用 webpack 编译为 javascript

• 当我使用 ts-node server.ts 运行服务器时,一切正常

• 使用 webpack 编译为 javascript 后,我​​的服务器中使用的 Firebase API 出现以下错误:

./node_modules/google-auto-auth/node_modules/mime/index.js 中的错误 找不到模块:错误:无法解析“/Users/XX/Desktop/XX/XX/node_modules/google-auto-auth/node_modules/mime”中的“./types/standard”

./node_modules/@google-cloud/storage/node_modules/mime/index.js 中的错误 找不到模块:错误:无法解析“/Users/XX/Desktop/XX/OM-XX/node_modules/@google-cloud/storage/node_modules/mime”中的“./types/standard”

等等。等等。

如何解决这个问题?

我的 webpack 配置代码:

const path = require('path');
const webpack = require('webpack');

module.exports = {
  entry: {server: './server.ts'},
  resolve: {extensions: ['.js', '.ts']},
  target: 'node',
  mode: 'none',
  // this makes sure we include node_modules and other 3rd party libraries
  externals: [/(node_modules|main\..*\.js)/],
  output: {
    path: __dirname,
    filename: '[name].js'
  },
  module: {
    rules: [
      {test: /\.ts$/, loader: 'ts-loader'}
    ]
  },
  plugins: [
    // Temporary Fix for issue: https://github.com/angular/angular/issues/11580
    // for "WARNING Critical dependency: the request of a dependency is an expression"
    new webpack.ContextReplacementPlugin(
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    )
  ]
}

谢谢!

【问题讨论】:

  • 我也在尝试同样的事情。你有任何解决方案@Mazlan Alam Malik???请帮帮我

标签: node.js angular typescript firebase webpack


【解决方案1】:

这可能与缺少类型有关?

尝试为所有抛出错误的包安装缺少的类型

例如:npm install --save @types/google-cloud__storage

【讨论】:

  • 我刚试过你的建议,还是不行。谢谢你的建议。
猜你喜欢
  • 2018-05-28
  • 2013-12-11
  • 1970-01-01
  • 2021-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
相关资源
最近更新 更多