将(es6) firebase 3 npm模块导入角的问题

时间:2021-05-30 19:42:53

For some reason, the Angular is saying that it cannot find the firebase module? No problem importing other module in the same fashion.

由于某种原因,角的意思是它找不到火基模块?以同样的方式导入其他模块没有问题。

import angular from 'angular';

// angular modules
import constants from './constants';
import onConfig  from './on_config';
import onRun     from './on_run';
import 'angular-ui-router';
import 'firebase/app'
import './templates';
import './filters';
import './controllers';
import './services';
import './directives';

// create and bootstrap application
const requires = [
  'firebase',  
  'ui.router',
  'templates',
  'app.filters',
  'app.controllers',
  'app.services',
  'app.directives'
];

window.app = angular.module('app', requires);

Has anyone else encountered this problem, or have any suggestion where I might be going wrong?

有没有人遇到过这个问题,或者有什么建议我哪里出了问题?

I'm importing this file which I believe should load the correct library

我正在导入这个文件,我认为应该装载正确的库

/**
 *  Firebase app for browser npm package.
 *
 * Usage:
 *
 *   firebase = require('firebase/app');
 */
require('./firebase-app');
module.exports = firebase;

Here is the classic error

这是一个典型的错误

Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module firebase due to:
Error: [$injector:nomod] Module 'firebase' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

2 个解决方案

#1


2  

You can import the whole module with:

您可以通过以下方式导入整个模块:

   import * as firebase from 'firebase'

#2


0  

I'm confused: the es6 module path needs to end in .js and begin with a relative or global path, i.e. ./ or ../ or http://path/to/dir/

我很困惑:es6模块路径需要以.js结尾,并以相对的或全局的路径开始,即…/或http://path/to/dir/

Possibly there is preprocessing of some sort that "legalizes" the OP's paths? Or is this just Angular's import?

可能存在某种预处理,使OP的路径“合法化”?或者这只是角的意义?

If real es6 modules, the changes suggested will work on browsers supporting modules.

如果是真正的es6模块,建议的更改将适用于支持模块的浏览器。

#1


2  

You can import the whole module with:

您可以通过以下方式导入整个模块:

   import * as firebase from 'firebase'

#2


0  

I'm confused: the es6 module path needs to end in .js and begin with a relative or global path, i.e. ./ or ../ or http://path/to/dir/

我很困惑:es6模块路径需要以.js结尾,并以相对的或全局的路径开始,即…/或http://path/to/dir/

Possibly there is preprocessing of some sort that "legalizes" the OP's paths? Or is this just Angular's import?

可能存在某种预处理,使OP的路径“合法化”?或者这只是角的意义?

If real es6 modules, the changes suggested will work on browsers supporting modules.

如果是真正的es6模块,建议的更改将适用于支持模块的浏览器。