gpt4 book ai didi

typescript - typescript 文件中的 module.exports 返回 'module is not a module.'

转载 作者:行者123 更新时间:2023-12-05 06:21:19 27 4
gpt4 key购买 nike

以下模块用JS文件编写:

module.exports = {
propA: 1,
propB: 2
}

允许稍后从模块导入属性,如:从“路径/到/模块”导入 { propA}

然而,将文件格式更改为 module.ts 之类的 typescript 会导致以下问题 linter 问题“模块不是模块”。

这是项目的tsconfig

{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"sourceMap": true,
"noImplicitThis": true,
"baseUrl": ".",
"types": [
"webpack-env",
"jest"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}

如果有人可以建议一种有效的方法来保留 module.exports 或在 typescript 中,我将不胜感激:)

...或者至少有可能以稍后允许仅导入其单个属性的方式声明导出对象的模块

最佳答案

像这样尝试:

export const yourData = {
propA: 1,
propB: 2
}

并从 'yourSrc' 导入 yourData

关于typescript - typescript 文件中的 module.exports 返回 'module is not a module.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59868540/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com