简体   繁体   English

导入不适用于Angular 2应用程序

[英]Imports not working in Angular 2 application

When I say imports are not working, I'm referring to a specific type of import: that from @types in the format import * as _ from 'lodash' . 当我说导入不起作用时,我指的是一种特定类型的导入:来自@types的格式为import * as _ from 'lodash' However, I can get around this by doing: import _ from 'lodash' . 但是,我可以通过这样做来解决这个问题: import _ from 'lodash' Which i have been doing up until now. 到目前为止我一直在做的事情。

This is well documented in this thread: Importing lodash into angular2 + typescript application , in which many different people have posted whether one import works and the other doesn't. 这个线程中有详细记载: 将lodash导入angular2 + typescript应用程序 ,其中许多不同的人发布了一个导入是否有效而另一个不导入。 This question is about identifying why that is the case. 这个问题是关于确定原因的原因

Up until now, this hasn't been a problem, but now that I'm trying to use the https://github.com/angular/angularfire2 package, it has become a problem because I now have to edit the node package and replace: import * as firebase from 'firebase'; 到目前为止,这不是一个问题,但现在我正在尝试使用https://github.com/angular/angularfire2包,它已经成为一个问题,因为我现在必须编辑节点包和替换: import * as firebase from 'firebase'; with import firebase from 'firebase' , otherwise it doesn't know 'firebase' is. import firebase from 'firebase' ,否则它不知道'firebase'是。

If I log the object returns from the firebase end in ./node_modules/angularfire2/auth/firebase_sdk_auth_backend.js I get: 如果我在./node_modules/angularfire2/auth/firebase_sdk_auth_backend.js记录对象从./node_modules/angularfire2/auth/firebase_sdk_auth_backend.js端返回,我得到:

在此输入图像描述

If I switch it to import firebase from 'firebase' the application loads and the log is: 如果我将其切换为import firebase from 'firebase'则应用程序加载并且日志为:

在此输入图像描述

I have been messing around with my tsconfig.json but to no avail. 我一直在搞乱我的tsconfig.json但无济于事。 ie by changing es2015 to ES6 and switching flags on and off. 即通过将es2015更改为ES6并打开和关闭标志。 The current (faulty) state of it is (and I'm presuming the issue is in here, though I'm not sure): 它的当前(错误)状态是(我假设问题在这里,虽然我不确定):

  {
    "compilerOptions": {
      "allowSyntheticDefaultImports": true,
      "declaration": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "lib": [
        "dom", "es2015"
      ],
      "module": "es2015",
      "moduleResolution": "node",
      "sourceMap": true,
      "target": "es5"
    },
    "include": ["src/**/*.ts"],
    "exclude": ["node_modules"],
    "compileOnSave": false,
    "atom": {
      "rewriteTsconfig": false
    }
  }

npm -v (4.0.2) <=> tsc -v (Version 2.0.10) <=> ionic -v (2.1.13) If there are any other package versions you need I'll post them in the comments below. npm -v(4.0.2)<=> tsc -v(版本2.0.10)<=>离子-v(2.1.13)如果您需要任何其他软件包版本,我会在下面的评论中发布它们。

It appears that I need to be able to import * as foo from 'bar' => what do I need to do to make that happen? 看来我需要能够import * as foo from 'bar' =>我需要做些什么来实现这一点?

NB This is also an ionic 2 app (but I don't think that makes too much difference) NB这也是一个离子2应用程序(但我不认为这会产生太大的差异)

From what I can tell, this is due to your @angular/compiler-cli version. 据我所知,这是由于你的@ angular / compiler-cli版本。 If you bump it to 2.1.1 it permits the import * as firebase from 'firebase' type. 如果你将它碰到2.1.1它允许从'firebase'类型导入*作为firebase。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular Universal CSS导入不起作用 - Angular Universal CSS imports not working 使用〜(波浪号)的SCSS文件导入在Angular 6中不起作用 - SCSS file imports using ~ (tilde) is not working in Angular 6 ES6的必要导入,以便在IE11上运行Angular 4应用程序 - Necessary imports for ES6 to run Angular 4 application on IE11 在Angular(4)中使用拆分的应用程序模块处理导入(客户端,服务器,共享) - Working with imports with split app modules in Angular(4) (client, server, shared) 升级 Angular 9 后共享模块的导入在共享组件中不起作用 - Imports of Shared Module not working in Shared components after upgrading Angular 9 Google fonts 导入不适用于 Angular 材料生产构建 - Google fonts imports not working on Angular Material production build Angular Ionic 应用 RouterLink 不工作,尽管 RouterLink 导入 - Angular Ionic app RouterLink not working despite RouterLink imports Angular 5应用程序在Angular 6上无法正常工作 - Angular 5 application is not working properly on Angular 6 角混合应用程序无法正常工作 - Angular hybrid application is not working 注射不适用于角度应用 - The injection is not working in angular application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM