首页 > 解决方案 > 条件导入 Deno

问题描述

我希望我的配置文件是可选的,我想到了这个解决方案,检查配置文件是否存在并有条件地导入我的配置文件,但我得到An import declaration can only be used in a namespace or module.deno-ts(1232).

app.ts

import {existsSync} from 'https://deno.land/std/fs/mod.ts'

if (existsSync('./myconfig.ts')) {
  import {config} from './myconfig.ts'
}

myconfig.ts

export const config: any = {
  config: "value"
}

标签: javascripttypescriptdeno

解决方案


推荐阅读