升级webpack5以后导入导出报错

// custom.config.json
{
  "orderLimit": {
    "group_ids": ["123456"],
    "desc": ["开发group_id"]
  }
}

// 引用custom.config.json的ts文件
import { orderLimit } from '../../../custom.config.json'

在升级webpack5之前上面这种写法是可以的。但是升级webpack5以后,就报错了:

WARNING in ./src/pages/customer/society/catering_customer_management/detail/store.ts 215:40-69
export 'orderLimit'.'group_ids'.'includes' (imported as 'orderLimit') was not found in '../../../custom.config.json' (possible exports: 0, 1, 2)

需要改成下面这种写法才不会报错:

import customJson from '../../../custom.config.json'

const orderLimit = customJson.orderLimit

另外下面这种写法的导出也报错了:

/** index.ts **/
const getLocaleWithModuleMap = (): string => {
  // ...
}
export {
  getLocaleWithModuleMap
}


/** 导入index.ts的文件 **/
import { getLocaleWithModuleMap } from '../../index'
WARNING in ./node_modules/gm_api/src/wechat/lng/index.ts 17:9-31
export 'getLocaleWithModuleMap' (imported as 'getLocaleWithModuleMap') was not found in '../../index' (module has no exports)

请问这是什么原因呢

阅读 1.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进