Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Typescript:导入使用module.exports导出的内容_Javascript_Reactjs_Typescript - Fatal编程技术网

Javascript Typescript:导入使用module.exports导出的内容

Javascript Typescript:导入使用module.exports导出的内容,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,我有以下主题文件,出于某种原因需要用ES5编写: module.exports.theme={ 原色:“蓝色”, 边框大小:“2px”, // ... } 我想将其导入一个Typescript文件(在createreact应用程序环境中)。因此,我做了以下工作: 从“../../../../session/theme”导入{theme}; 这将导致以下错误: Attempted import error: 'theme' is not exported from '../../../../s

我有以下主题文件,出于某种原因需要用ES5编写:

module.exports.theme={
原色:“蓝色”,
边框大小:“2px”,
// ...
}
我想将其导入一个Typescript文件(在createreact应用程序环境中)。因此,我做了以下工作:

从“../../../../session/theme”导入{theme};
这将导致以下错误:

Attempted import error: 'theme' is not exported from '../../../../session/theme'.
我还尝试使用
module.exports.default={…}
导出并导入默认值,但它基本上说明了相同的事情(没有默认导出)

我应该如何解决这个问题

我的
tsconfig.json
如下所示:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": ["src"]
}

当您的模块使用ES5编译时,您必须使用require而不是import。 试试这个

否则,您需要使用ES6编译模块,您是说“使用ES5编译”,还是说“使用ES5编译”?
const theme = require('../../../../session/theme').theme;