【发布时间】:2023-03-24 05:01:01
【问题描述】:
当我说导入不起作用时,我指的是一种特定类型的导入:来自@types,格式为import * as _ from 'lodash'。但是,我可以通过这样做来解决这个问题:import _ from 'lodash'。到目前为止我一直在做的事情。
这在此线程中有很好的记录:Importing lodash into angular2 + typescript application,其中许多不同的人发布了一个导入是否有效而另一个无效。这个问题是关于确定为什么会出现这种情况。
到目前为止,这还不是问题,但现在我正在尝试使用https://github.com/angular/angularfire2 包,它已经成为问题,因为我现在必须编辑节点包并替换:import * as firebase from 'firebase'; import firebase from 'firebase',否则它不知道 'firebase' 是什么。
如果我在 ./node_modules/angularfire2/auth/firebase_sdk_auth_backend.js 中记录从 firebase 端返回的对象,我会得到:
如果我将其切换到import firebase from 'firebase',应用程序会加载并且日志是:
我一直在搞乱我的tsconfig.json,但无济于事。即通过将 es2015 更改为 ES6 并打开和关闭标志。它的当前(故障)状态是(我假设问题就在这里,尽管我不确定):
{
"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 (版本 2.0.10) ionic -v (2.1.13) 如果您需要任何其他软件包版本,我会将它们发布在下面的 cmets 中。
看来我需要能够import * as foo from 'bar' => 我需要做什么才能做到这一点?
注意 这也是一个 ionic 2 应用程序(但我认为这没有太大区别)
【问题讨论】:
标签: angular typescript import ionic2