我正试图将此模块导入到我的Typescript文件中,但它引发了一个关于如何导入模块的错误。这是一个谷歌Firebase函数脚本,但我正在项目代码的其他区域导入这个模块。
10 const flamelinkApp = flamelink({
~~~~~~~~~
src/index.ts:3:1
3 import * as flamelink from 'flamelink/app';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
NMy Typescript配置文件在这里:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"esModuleInterop": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
您会看到esModuleInterop
标志被设置为true,这应该可以解决这个问题。
我也尝试过这样的导入:import flamelink from 'flamelink/app';
并得到这个错误:
Module '"/Users/leeprobert/Documents/dev/PebbleStudios/Sciex/Grace/dev/pebble_sciex_grace_react/client/functions/node_modules/flamelink/public"' can only be default-imported using the 'esModuleInterop' flagts(1259)
public.d.ts(61, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
有什么想法吗?
根据警告消息,我们似乎需要导入模块的默认值,而不是在命名空间中。你能试试这个吗?
import flamelink from 'flamelink/app'