[英]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.